Registry / database / django-extended-choices

django-extended-choices

JSON →
library1.3.3pypypiunverified

A Django helper to define choices for model fields in a more readable and maintainable way, with support for grouping, named constants, and easy iteration. Current version 1.3.3, maintenance mode with occasional bug fixes.

pip install django-extended-choices
INSTALL
IMPORT
SIG · DJANGO-EXTENDED-CH
D
django-extended-choices
databasepythonv1.3.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

Choices
from extended_choices import Choices
from django_extended_choices.choices import Choices

Define choices using tuples with constant name, value, and display label, then use in model field.

from django.db import models from django_extended_choices.choices import Choices class Pizza(models.Model): CRUST_THIN = 'thin' CRUST_THICK = 'thick' ORGANIC = 'organic' CRUSTS = Choices( ('STANDARD', 'Standard', 'Standard crust'), ('THIN', 'Thin', 'Thin crust'), ('THICK', 'Thick', 'Thick crust'), ) crust = models.CharField(max_length=10, choices=CRUSTS) custom_choice = models.CharField(max_length=20, choices=Choices('A', 'B'))
Debug
Known issues
breakingIn version 1.0, the package renamed from django_extended_choices to django-extended-choices on PyPI, and imports changed. Old 'django_extended_choices' imports still work with the new package? Actually, the package name changed on PyPI but the module remains django_extended_choices. Check your requirements.
fix
Update your requirements to django-extended-choices>=1.0.0 and ensure imports use 'django_extended_choices'.
affects: <1.0
gotchaNamedValuesChoices deprecation: In version 1.3, NamedValuesChoices is deprecated and may be removed. Use Choices instead which covers all use cases.
fix
Replace NamedValuesChoices with Choices.
affects: >=1.3,<2.0
gotchaIf you define a constant with the same name as a choice constant (e.g., CRUST_THIN), the order of definition matters: the constant is overridden by the choice when iterating? Actually, constants defined before Choices are preserved. Be careful with naming clashes.
fix
Prefix your model constants or use different names to avoid confusion.
affects: all
Upgrade
Version history
1.3.3latest on PyPI · released Apr 16, 2019
Audit
Dependencies
djangorequiredRequired integration with Django models and fields
Agent activity
8 hits · last 30 days
node
8
Resources
django-extended-choices — pip install django-extended-choices · libregistry