@@ -84,8 +84,13 @@ By default `DRF ModelSerializer
8484`ChoiceField <https://www.django-rest-framework.org/api-guide/fields/#choicefield >`_ to represent an
8585:class: `~django_enum.fields.EnumField `. This works great, but it will not accept :ref: `symmetric
8686enumeration values <enum-properties:howto_symmetric_properties>`. A serializer field
87- :class: `~django_enum.drf.EnumField ` is provided that will. The dependency on DRF _ is optional so
88- to use the provided serializer field you must install DRF _:
87+ :class: `django_enum.drf.EnumField ` is provided that will. :class: `~django_enum.fields.FlagField `
88+ fields do not work well with DRF's builtin
89+ `MultipleChoiceField <https://www.django-rest-framework.org/api-guide/fields/#multiplechoicefield >`_
90+ so we provide also provide a :class: `django_enum.drf.FlagField `.
91+
92+ The dependency on DRF _ is optional so to use the provided serializer field you must install DRF _:
93+
8994
9095.. code :: bash
9196
@@ -97,7 +102,7 @@ to use the provided serializer field you must install DRF_:
97102
98103
99104
100- The serializer :class: `~ django_enum.drf.EnumField ` accepts any arguments that
105+ The serializer :class: `django_enum.drf.EnumField ` accepts any arguments that
101106`ChoiceField <https://www.django-rest-framework.org/api-guide/fields/#choicefield >`_ does. It also
102107accepts the ``strict `` parameter which behaves the same way as it does on the model field.
103108
@@ -110,14 +115,28 @@ accepts the ``strict`` parameter which behaves the same way as it does on the mo
110115 2. You have non-strict model fields and want to allow your API to accept values outside of
111116 the enumeration.
112117
118+ The :class: `django_enum.drf.EnumField ` must be used for any :class: `~django_enum.fields.FlagField `
119+ fields. It will accept a composite integer or a list of any values coercible to a flag. The
120+ serialized output will be an composite integer holding the full bitfield.
121+
122+ ModelSerializers
123+ ~~~~~~~~~~~~~~~~
124+
125+ An :class: `django_enum.drf.EnumFieldMixin ` class is provided that when added to
126+ `ModelSerializers <https://www.django-rest-framework.org/api-guide/serializers/#modelserializer >`_
127+ will be sure that the serializer instantiates the correct django-enum serializer field type:
128+
129+ .. literalinclude :: ../../../tests/examples/drf_modelserializer_howto.py
130+ :lines: 3-
131+
113132.. _filtering :
114133
115134django-filter
116135-------------
117136
118137As shown above, filtering by any value, enumeration type instance or symmetric value works with
119138:doc: `Django's ORM <django:topics/db/queries >`. This is not natively true for the default
120- :doc: ` FilterSet < django-filter:ref/ filterset> ` from :doc: `django-filter <django-filter:index >`.
139+ :class: ` django_filters. filterset.FilterSet ` from :doc: `django-filter <django-filter:index >`.
121140Those filter sets will only be filterable by direct enumeration value by default. An
122141:class: `~django_enum.filters.EnumFilter ` class is provided to enable filtering by symmetric property
123142values, but since the dependency on :doc: `django-filter <django-filter:index >` is optional, you must
@@ -128,11 +147,24 @@ first install it:
128147 pip install django-filter
129148
130149 .. literalinclude :: ../../../tests/examples/filterfield_howto.py
131- :lines: 3 -
150+ :lines: 2 -
132151
133- An :class: `~django_enum.filters.FilterSet ` class is also provided that uses
152+ A :class: `~django_enum.filters.FilterSet ` class is also provided that uses
134153:class: `~django_enum.filters.EnumFilter ` for :class: `~django_enum.fields.EnumField ` by default.
135154So the above is also equivalent to:
136155
137156.. literalinclude :: ../../../tests/examples/filterset_howto.py
138157 :lines: 3-
158+
159+ .. tip ::
160+
161+ :class: `~django_enum.filters.FilterSet ` may also be used as a mixin.
162+
163+
164+ FlagFields
165+ ~~~~~~~~~~
166+
167+ An :class: `~django_enum.filters.EnumFlagFilter ` field for flag fields is also provided:
168+
169+ .. literalinclude :: ../../../tests/examples/flagfilterfield_howto.py
170+ :lines: 2-
0 commit comments