This package lets you use real Python (PEP435-style) enums with Django.
django-enumfields2 is a friendly drop-in fork of hzdg/django-enumfields that’s still maintained.
Installation
pip install django-enumfields2
Included Tools
EnumField, EnumIntegerField
from enumfields import EnumField
from enum import Enum
class Color(Enum):
RED = 'r'
GREEN = 'g'
BLUE = 'b'
class MyModel(models.Model):
color = EnumField(Color, max_length=1)
Elsewhere:
m = MyModel.objects.filter(color=Color.RED)
EnumIntegerField works identically, but the underlying storage mechanism is an IntegerField instead of a CharField.
Usage in Forms
Call the formfield method to use an EnumField directly in a Form.
class MyForm(forms.Form):
color = EnumField(Color, max_length=1).formfield()
Enum
Normally, you just use normal PEP435-style enums, however, django-enumfields also includes its own version of Enum with a few extra bells and whistles. Namely, the smart definition of labels which are used, for example, in admin dropdowns. By default, it will create labels by title-casing your constant names. You can provide custom labels with a nested “Labels” class.
from enumfields import EnumField, Enum # Our own Enum class
class Color(Enum):
RED = 'r'
GREEN = 'g'
BLUE = 'b'
class Labels:
RED = 'A custom label'
class MyModel(models.Model):
color = EnumField(Color, max_length=1)
assert Color.GREEN.label == 'Green'
assert Color.RED.label == 'A custom label'
EnumFieldListFilter
enumfields.admin.EnumFieldListFilter is provided to allow using enums in list_filter.
from enumfields.admin import EnumFieldListFilter
class MyModelAdmin(admin.ModelAdmin):
list_filter = [('color', EnumFieldListFilter)]
Django Rest Framework integration
EnumSupportSerializerMixin mixin allows you to use enums in DRF serializers.
# models.py
from enumfields import EnumField
from enum import Enum
class Color(Enum):
RED = 'r'
GREEN = 'g'
BLUE = 'b'
class MyModel(models.Model):
color = EnumField(Color, max_length=1)
# serializers.py
from enumfields.drf.serializers import EnumSupportSerializerMixin
from rest_framework import serializers
from .models import MyModel
class MyModelSerializer(EnumSupportSerializerMixin, serializers.ModelSerializer):
class Meta:
model = MyModel
fields = '__all__'
Metadata
Release files for django-enumfields2 4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_enumfields2-4.0.tar.gz | 7.7 kB | With provenance | Details for django_enumfields2-4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_enumfields2-4.0-py3-none-any.whl | Python 3 | none | any | Details for django_enumfields2-4.0-py3-none-any.whl |
Total release size: 17.9 kB
Release files / django_enumfields2-4.0.tar.gz
| Download URL | django_enumfields2-4.0.tar.gz |
|---|---|
| Size | 7.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f41d84a3ba166f9148df073e17f8ec040b7ce5207b8d60cfa061205820cc366c
|
|
BLAKE2b-256 checksum How to use checksums |
c4f4ed7494841b06f0086f933c207bb11f6b4fe9550953f07ef2a971b0452e50
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 24, 2026.
Transparency logRelease files / django_enumfields2-4.0-py3-none-any.whl
| Download URL | django_enumfields2-4.0-py3-none-any.whl |
|---|---|
| Size | 10.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
136a7f8fe53ae73cb05d23c5d94484f9e5f26a312fbeb954c476d67b78a88fcf
|
|
BLAKE2b-256 checksum How to use checksums |
6de79944b7c8d783bfd6e825c05cc873f66463ee0e3cc4cecb1e7685c884441d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 24, 2026.
Transparency logSecurity for django-enumfields2 4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for django_enumfields2-4.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 24, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.