|
30 | 30 | .. _enumerations: https://docs.python.org/3/library/enum.html#enum.Enum
|
31 | 31 | .. _ValueError: https://docs.python.org/3/library/exceptions.html#ValueError
|
32 | 32 | .. _DRY: https://en.wikipedia.org/wiki/Don%27t_repeat_yourself
|
| 33 | +.. _enum-properties: <https://pypi.org/project/enum-properties/> |
| 34 | +.. _django-enum: <https://django-enum.readthedocs.io/en/latest/>: |
33 | 35 |
|
34 | 36 | Django Enum
|
35 | 37 | ###########
|
36 | 38 |
|
37 | 39 | Full and natural support for enumerations_ as Django model fields.
|
38 | 40 |
|
39 |
| -`django-enum <https://django-enum.readthedocs.io/en/latest/>`_ works in concert |
40 |
| -with Django_'s built in ``TextChoices`` and ``IntegerChoices`` to provide a new |
41 |
| -model field type, ``EnumField``, that resolves the correct native Django_ field |
42 |
| -type for the given enumeration based on its value type and range. For example, |
43 |
| -``IntegerChoices`` that contain values between 0 and 32767 become |
44 |
| -`PositiveSmallIntegerField <https://docs.djangoproject.com/en/stable/ref/models/fields/#positivesmallintegerfield>`_. |
| 41 | +Many packages aim to ease usage of Python enumerations as model fields. Most |
| 42 | +were made obsolete when Django provided ``TextChoices`` and ``IntegerChoices`` |
| 43 | +types. The motivation for django-enum_ was to: |
| 44 | + |
| 45 | +* Always automatically coerce fields to instances of the Enum type. |
| 46 | +* Allow strict adherence to Enum values to be disabled. |
| 47 | +* Handle migrations appropriately. (See `migrations <https://django-enum.readthedocs.io/en/latest/usage.html#migrations>`_) |
| 48 | +* Integrate as fully as possible with Django_'s existing level of enum support. |
| 49 | +* Integrate with enum-properties_ to enable richer enumeration types. |
| 50 | +* Represent enum fields with the smallest possible column type. |
| 51 | +* Be as simple and light-weight an extension to core Django as possible. |
| 52 | + |
| 53 | +django-enum_ works in concert with Django_'s built in ``TextChoices`` and |
| 54 | +``IntegerChoices`` to provide a new model field type, ``EnumField``, that |
| 55 | +resolves the correct native Django_ field type for the given enumeration based |
| 56 | +on its value type and range. For example, ``IntegerChoices`` that contain |
| 57 | +values between 0 and 32767 become `PositiveSmallIntegerField <https://docs.djangoproject.com/en/stable/ref/models/fields/#positivesmallintegerfield>`_. |
45 | 58 |
|
46 | 59 | .. code:: python
|
47 | 60 |
|
|
0 commit comments