You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Many packages aim to ease usage of Python enumerations as model fields. Most
10
+
were made obsolete when Django provided ``TextChoices`` and ``IntegerChoices``
11
+
types. The motivation for django-enum was to:
12
+
13
+
* Always automatically coerce fields to instances of the Enum type.
14
+
* Allow strict adherence to Enum values to be disabled.
15
+
* Handle migrations appropriately. (See `migrations <https://django-enum.readthedocs.io/en/latest/usage.html#migrations>`_)
16
+
* Integrate as fully as possible with Django_'s existing level of enum support.
17
+
* Integrate with enum-properties_ to enable richer enumeration types.
18
+
* Represent enum fields with the smallest possible column type.
19
+
* Be as simple and light-weight an extension to core Django as possible.
20
+
21
+
django-enum works in concert with Django_'s built in ``TextChoices`` and
22
+
``IntegerChoices`` to provide a new model field type, ``EnumField``, that
23
+
resolves the correct native Django_ field type for the given enumeration based
24
+
on its value type and range. For example, ``IntegerChoices`` that contain
25
+
values between 0 and 32767 become `PositiveSmallIntegerField <https://docs.djangoproject.com/en/stable/ref/models/fields/#positivesmallintegerfield>`_.
15
26
16
27
.. code:: python
17
28
@@ -68,7 +79,7 @@ enum-properties_ which makes possible very rich enumeration fields.
68
79
from django_enum import TextChoices # use instead of Django's TextChoices
0 commit comments