Serializers

Currently only provides ModelSerializer for model-based data manipulation.

To use, import like so:

from dynamicforms.serializers import ModelSerializer

Make sure you don’t import DRF’s ModelSerializer over this one.

Class reference

class ModelSerializer(*args, is_filter: bool = False, **kwds)[source]

DynamicForms’ ModelSerializer overrides the following behaviour over DRF’s implementation:

  • Uses own field types for construction
  • Adds form UUID (rendered in html too)
  • Adds processing for form-wide errors

DRF’s docstring copied verbatim:

A ModelSerializer is just a regular Serializer, except that:

  • A set of default fields are automatically populated.
  • A set of default validators are automatically populated.
  • Default .create() and .update() implementations are provided.

The process of automatically determining a set of serializer fields based on the model fields is reasonably complex, but you almost certainly don’t need to dig into the implementation.

If the ModelSerializer class doesn’t generate the set of fields that you need you should either declare the extra/differing fields explicitly on the serializer class, or simply use a Serializer class.

get_extra_kwargs()[source]

Return a dictionary mapping field names to a dictionary of additional keyword arguments.

manage_changed_flds()[source]

When there is a need to only change few parameters of a field put those fields and changed parameters in serializers Meta class in parameter changed_flds.

Example:

changed_flds = {
    'id': dict(display=DisplayMode.HIDDEN),
    'comment': dict(label='Comm', help_text='Help text for comment field')
}
Returns:
serializer_choice_field

alias of dynamicforms.fields.ChoiceField

alias of dynamicforms.fields.PrimaryKeyRelatedField

alias of dynamicforms.fields.SlugRelatedField

serializer_url_field

alias of dynamicforms.fields.HyperlinkedIdentityField