Registry / web-framework / django-choices-field

django-choices-field

JSON →
library4.0.0pypypi✓ verified 83d ago

A Django field that directly sets/gets Django's TextChoices/IntegerChoices enum values, eliminating manual conversion between enum members and database values. Version 4.0.0 requires Python >=3.10, Django <4.0, and drops support for Python 3.8/3.9. Released irregularly, with breaking changes in v4.0.0 including strict blank/null validation and type checking utilities.

pip install django-choices-field
INSTALL
IMPORT
SIG · DJANGO-CHOICES-FIE
D
django-choices-field
web-frameworkpythonv4.0.0
Install
3.4s avg
Import
—
Disk
66MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v4.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 66.3MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 3.4s · import 0.000s · 67MB
66MB installed
● package 66MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

IntegerChoicesField
✓ from django_choices_field import IntegerChoicesField
✗ from choices_field import ChoicesField
TextChoicesField
✓ from django_choices_field import TextChoicesField
✗ from choices_field import ChoicesField
IntegerChoicesFlag
✓ from django_choices_field import IntegerChoicesFlag
✗ from choices_field import ChoicesField

Define a model with a ChoicesField using Django's TextChoices enum.

from django.db import models from django.utils.translation import gettext_lazy as _ from choices_field import ChoicesField class MyModel(models.Model): class Status(models.TextChoices): DRAFT = 'DRAFT', _('Draft') PUBLISHED = 'PUBLISHED', _('Published') status = ChoicesField(choices_enum=Status, default=Status.DRAFT) obj = MyModel(status=MyModel.Status.PUBLISHED) print(obj.status) # MyModel.Status.PUBLISHED print(obj.status.value) # 'PUBLISHED'
Debug
Known issues
breakingIn v4.0.0, passing blank=True without null=True raises ImproperlyConfigured. Previously it was allowed but could cause data integrity issues.
fix
Always set null=True when blank=True, or omit blank=True if not needed.
affects: >=4.0.0
deprecatedPassing choices as a plain list/tuple in the field constructor is deprecated and will be removed in a future version. Use choices_enum instead.
fix
Define a ChoicesEnum subclass and pass it to the choices_enum parameter.
affects: >=4.0.0
gotchaThe get_FIELD_display() method works out of the box, but in versions prior to 3.1.1 it was broken for enum fields (returned value instead of label).
fix
Upgrade to >=3.1.1, or manually override get_FIELD_display() if stuck on older version.
affects: <3.1.1
gotchaChoicesField does not support null=False and blank=False if the enum does not have a default; you must either set a default or allow null/blank.
fix
Provide a default argument (e.g., default=MyEnum.FOO) or set null=True and/or blank=True.
affects: >=4.0.0
Upgrade
Version history
4.0.0latest on PyPI · released Dec 27, 2025
Audit
Dependencies
djangorequiredCore dependency for Django fields framework
Agent activity
10 hits · last 30 days
node
10
Resources
django-choices-field — pip install django-choices-field · libregistry