Form Fields¶
The documentation foradmin_kit.fields
module.
MultiSelect Form Field¶
MultiSelectField
provides Multi Selecting features. It is same as models.MultiSelectField, but is used inDjango Admin Forms
Parameters
seperator
The default is
,
. This value will be used as a delimiter while storing the selected values.
choices
The choices used for rendering. This field is optional as the choices can be from an ajax class
ajax_source
The
key
name used while registering inheritedadmin_kit.ajax.Ajax
class. The return of itsrun
method will be used as choices.
ajax_target
This will be of the form
key_name:target_field
. On every change in its input, it hits the inheritedadmin_kit.ajax.Ajax
class mapped to the specifiedkey_name
. Iftarget_field
is 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_subscribe
This parameter is paired with
ajax_source
parameter and is set toFalse
. If it isTrue
, then this field is linked to every other field with itsajax_source
value same as its linkedajax_target
value.But it wont be linked to fields which have
target_field
specified in itsajax_target
parameter.
kit_config
This defaults to
None
. Instead of passingajax_source
,ajax_target
andajax_subscribe
seperately, 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.