Form Fields¶
The documentation foradmin_kit.fieldsmodule.
MultiSelect Form Field¶
MultiSelectFieldprovides Multi Selecting features. It is same as models.MultiSelectField, but is used inDjango Admin FormsParameters
seperatorThe default is
,. This value will be used as a delimiter while storing the selected values.
choicesThe choices used for rendering. This field is optional as the choices can be from an ajax class
ajax_sourceThe
keyname used while registering inheritedadmin_kit.ajax.Ajaxclass. The return of itsrunmethod will be used as choices.
ajax_targetThis will be of the form
key_name:target_field. On every change in its input, it hits the inheritedadmin_kit.ajax.Ajaxclass mapped to the specifiedkey_name. Iftarget_fieldis specified then it sets the value of specified model field to api’s return value.The selected values will be passed as
q[]query list parameter.
ajax_subscribeThis parameter is paired with
ajax_sourceparameter and is set toFalse. If it isTrue, then this field is linked to every other field with itsajax_sourcevalue same as its linkedajax_targetvalue.But it wont be linked to fields which have
target_fieldspecified in itsajax_targetparameter.
kit_configThis defaults to
None. Instead of passingajax_source,ajax_targetandajax_subscribeseperately, one can specify them in a dictionary and can be passed to this parameter.Example
# admin.py ... from admin_kit.fields import MultiSelectField class BookForm(forms.ModelForm): model = Book selected_fields = MultiSelectField(ajax_source='genres', ajax_subscribe=True) fields = ('name', 'genres') class BookAdmin(nested_admin.NestedStackedInline): model = Book form = BookFormis equivalent to
# admin.py ... from admin_kit.fields import MultiSelectField class BookForm(forms.ModelForm): model = Book kit_config = { 'ajax-source': 'genres', 'ajax-subscribe': True } selected_fields = MultiSelectField(kit_config=kit_config) fields = ('name', 'genres') class BookAdmin(nested_admin.NestedStackedInline): model = Book form = BookFormNote
Make sure the key names are hiphen seperated.
Select Form Field¶
SelectFieldprovides Selecting features. It is similar toMultiSelectField, but provides a single value to select.Parameters
choicesajax_sourceajax_targetajax_subscribekit_config