A field is part of a category. It defines type and constraints for one property of a contribution.
The following types are available:
TextField
for text input.NumericField
for numeric input.DateTimeField
for input of date and time.DateField
for date-only inputs.TimeField
for time-only inputs.LookupField
; a list of predefined values, the user can select exactly one.MultipleLookupField
; a list of predefined values, the user can select arbitrary number.Parameter | Type | Description |
---|---|---|
id |
int | Identifies the field in the database. |
name |
string | Short title of the field. |
description |
string | Longer description about the field. |
key |
string | The key is used as an identifier for the field, when exchanging contribution attributes via the API. |
required |
boolean | Indicates if a value for this field is required. |
category |
Category | Category this field is assigned to. |
order |
int | Position of the field in the list of fields for the category. |
status |
string | Status of the field. Must be one of active , inactive , deleted . Defaults to active . |
Parameter | Type | Description |
---|---|---|
maxlength |
int | Maximum number of characters accepted for the text field. |
textarea |
boolean | Indicates of the field should be displayed as a text box in the front-end. |
Parameter | Type | Description |
---|---|---|
minval |
float | Lowest accepted value for the field. |
maxval |
float | Largest accepted value for the field. |
Parameter | Type | Description |
---|---|---|
lookupvalues |
QuerySet | List of LookupValues |
Parameter | Description |
---|---|
type_name |
Human readable type of the field, e.g. “Date and time” |
fieldtype |
Type of the field, e.g. “DateTimeField” |
get_field_types()
Returns a list of fields types that are available to use.
list
>>> from geokey.categories.models import Field
>>> Field.get_field_types()
[TextField, NumericField, DateTimeField]
validate_input(value)
Validates the input against the field definition, i.e. the type and constraints.
validate_required(value)
Checks if an accepted value is provided if the field is required.
delete()
Deletes the field by setting its status to deleted
.
Field.create(name, description, key, required, category, field_type)
Field.create(
'Name of Restaurant',
'The name of the restaurant',
'name-of-restaurant'
True
category,
'TextField'
)
get_list(user, project_id, category_id)
Returns a list of all fields in a category that the user can access.
django.db.models.query.QuerySet: List of Fields
get_single(user, project_id, category_id, field_id)
Returns a single field.
Field
as_admin(user, project_id, category_id, field_id)
Returns a single field if the user is an administrator of the project.
Field