Skip to main content

django-richenum

Latest PyPI Version Python versions PyPI Downloads

About

A Django extension of richenum for Python. If you're unfamiliar with richenums, please read up on them (see Related Packages) before using django-richenum.

Model Fields

IndexEnumField
Store ints in DB, but expose OrderedRichEnumValues in Python.

CanonicalNameEnumField
Store varchar in DB, but expose RichEnumValues in Python.
We recommend that you use IndexEnumField for storage and query efficiency.

LaxIndexEnumField
Like IndexEnumField, but also allows casting to and from canonical names.
Mainly used to help migrate existing code that uses strings as database values.

Form Fields

CanonicalEnumField
Uses the RichEnum/OrderedRichEnum canonical_name as form field values.

IndexEnumField
Uses the OrderedRichEnum index as form field values.

Django Admin

RichEnumFieldListFilter
Enables filtering by RichEnum model fields in the Django admin UI.

Links

Installation

pip install django-richenum

Example Usage

IndexEnumField

>>> from richenum import OrderedRichEnum, OrderedRichEnumValue
>>> class MyOrderedRichEnum(OrderedRichEnum):
...    FOO = OrderedRichEnumValue(index=1, canonical_name="foo", display_name="Foo")
...    BAR = OrderedRichEnumValue(index=2, canonical_name="bar", display_name="Bar")
...
>>> from django.db import models
>>> from django_richenum.models import IndexEnumField
>>> class MyModel(models.Model):
...    my_enum = IndexEnumField(MyOrderedRichEnum, default=MyOrderedRichEnum.FOO)
...
>>> m = MyModel.objects.create(my_enum=MyOrderedRichEnum.BAR)
>>> m.save()
>>> m.my_enum
OrderedRichEnumValue - idx: 2  canonical_name: 'bar'  display_name: 'Bar'
>>> MyModel.objects.filter(my_enum=MyOrderedRichEnum.BAR)

CanonicalNameEnumField

>>> from richenum import RichEnum, RichEnumValue
>>> class MyRichEnum(RichEnum):
...    FOO = RichEnumValue(canonical_name="foo", display_name="Foo")
...    BAR = RichEnumValue(canonical_name="bar", display_name="Bar")
...
>>> from django.db import models
>>> from django_richenum.models import CanonicalNameEnumField
>>> class MyModel(models.Model):
...    my_enum = CanonicalNameEnumField(MyRichEnum, default=MyRichEnum.FOO)
...
>>> m = MyModel.objects.create(my_enum=MyRichEnum.BAR)
>>> m.save()
>>> m.my_enum
RichEnumValue - canonical_name: 'bar'  display_name: 'Bar'
>>> MyModel.objects.filter(my_enum=MyRichEnum.BAR)

RichEnumFieldListFilter

>>> from django_richenum.admin import register_admin_filters
>>> register_admin_filters()

Related Packages

richenum
Package implementing RichEnum and OrderedRichEnum that django-richenum depends on.

Notes

If you're using Django 1.7+, you'll need to use the @deconstructible decorator for your RichEnumValue and OrderedRichEnumValue classes so Django's migration framework knows how to serialize your RichEnumValue and OrderedRichEnumValue.

>>> from django.utils.deconstruct import deconstructible
>>> from richenum import RichEnumValue, OrderedRichEnumValue
>>> @deconstructible
... class CustomRichEnumValue(RichEnumValue):
...     pass
...
>>> @deconstructible
... class CustomOrderedRichEnumValue(OrderedRichEnumValue):
...     pass
...

Contributing

  1. Fork the repo from GitHub.
  2. Make your changes.
  3. Add unittests for your changes.
  4. Run make lint and make test.
  5. Add yourself to AUTHORS.md (in alphabetical order).
  6. Send a pull request from your fork to the main repo.

Changelog

5.2.0 (2026-03-16)

  • Add support for Python 3.14
  • Add support for Django 5.2
  • Drop support for Python versions below 3.11
  • Drop support for Django versions below 4.2

5.1.0 (2026-3-16)

  • Migrate to poetry

4.1.0 (2023-12-12)

  • Support for Django 4.2
  • Support for Python 3.11
  • Remove support for Django 2.2, 3.0, 3.1
  • Remove support for Python 3.7
  • Require MySQL 8 and Postgres 12

3.7.0 (2019-09-05)

  • Support for Django 2.3

3.6.0 (2019-07-09)

  • Support for Django 2.2
  • Support for Python 3.7
  • Remove support for Django 2.0

3.5.0 (2018-09-10)

3.4.0 (2018-02-10)

  • Drop support for old Django versions

3.3.0 (2018-01-21)

  • removed Python 3.4
  • add support for Python 3.6
  • add support for Django 2.0
  • Properly mark raw strings (used as regex)

3.2.0 (2016-08-22)

  • Python 3.4 & 3.5 support

3.1.0 (2015-08-02)

  • Django 1.10 support

3.0.1 (2015-07-13)

  • Prepare for python 3 support

2.4.1 (2015-05-04)

  • replace mysql client library (for tests)
  • stop using lambdas

2.3.0 (2015-05-04)

  • Support Django 1.8

2.2.0 (2015-03-11)

  • Support ModelForms for non-SQLite DB backends

2.1.0 (2014-11-01)

  • Support migration in Django 1.7

2.0.0 (2014-09-04)

  • Support Django 1.7, drop support for Python 2.6.

1.2.2 (2014-08-02)

  • Support Django 1.3

1.2.1 (2014-06-02)

  • Remove uses of BaseException.message.

1.2.0 (2013-12-03)

  • Add enum-aware versions of TypedMultipleChoiceField.

1.1.0 (2013-12-03)

  • Fix form fields to support Django 1.6 (while maintaining compatibility with 1.4 and 1.5).

1.0.2 (2013-11-05)

  • Make EnumField.run_validators a no-op. This stops some warnings from type comparison, and it doesn't seem useful in an EnumField context.

1.0.1 (2013-09-10)

  • Support South.

1.0.0 (2013-08-16)

  • Initial public release.

Release files for django-richenum 5.2.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-richenum 5.2.0
File Size Uploaded
django_richenum-5.2.0.tar.gz 10.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-richenum 5.2.0
File Interpreter ABI Platform
django_richenum-5.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 22.8 kB

Release files / django_richenum-5.2.0.tar.gz

Download URL django_richenum-5.2.0.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a9c7b0422713134f182a0178d876f6ca72f06283ca148405511fcfef763eb686
BLAKE2b-256 checksum
How to use checksums
9611b8422d21c315841539ff71f53290d81ef4c569714c045bc4ac2880ccd3cf
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 16, 2026.

Transparency log

Release files / django_richenum-5.2.0-py3-none-any.whl

Download URL django_richenum-5.2.0-py3-none-any.whl
Size 12.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
52edfb5d6fdf881220ea006fe350975342f0ca1119b27b57e4330258e80c62e0
BLAKE2b-256 checksum
How to use checksums
2b99ff85f4abd0322c2d21048c99de0e1b4cfdb24364ffc1d88636fc66386dc7
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 16, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

5.2.0 This release

2 release files

5.1.0

2 release files

5.0.0

2 release files

4.0.0

2 release files

3.8.0

2 release files

3.7.0

2 release files

3.6.0

2 release files

3.5.0

1 release file

3.4.0

1 release file

3.3.1

1 release file

3.2.1

1 release file

3.2.0

1 release file

3.1.0

1 release file

3.0.1

1 release file

2.4.0

1 release file

2.3.2

1 release file

2.3.1

1 release file

2.3.0

1 release file

2.2.0

1 release file

2.1.0

1 release file

2.0.0

2 release files

1.2.2

1 release file

1.2.1

1 release file

1.2.0

1 release file

1.1.0

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.1.0

1 release file

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