Skip to main content

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.

https://github.com/akx/django-enumfields2/actions/workflows/ci.yml/badge.svg https://img.shields.io/pypi/v/django-enumfields2.svg https://img.shields.io/pypi/pyversions/django-enumfields2.svg

Installation

  1. 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__'

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)

Source distribution for django-enumfields2 4.0
File Size Uploaded
django_enumfields2-4.0.tar.gz 7.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-enumfields2 4.0
File Interpreter ABI Platform
django_enumfields2-4.0-py3-none-any.whl Python 3 none any Details

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 log

Release 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 log

Release history Release notifications | RSS feed

This release

4.0 This release

2 release files

3.0.2

2 release files

3.0.1

2 release files

3.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page