{"id":23562,"library":"django-choices-field","title":"Django Choices Field","description":"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.","status":"active","version":"4.0.0","language":"python","source_language":"en","source_url":"https://github.com/bellini666/django-choices-field","tags":["django","choices","enum","textchoices","integerchoices","field"],"install":[{"cmd":"pip install django-choices-field","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Core dependency for Django fields framework","package":"django","optional":false}],"imports":[{"wrong":"from choices_field import ChoicesField","symbol":"IntegerChoicesField","correct":"from django_choices_field import IntegerChoicesField"},{"wrong":"from choices_field import ChoicesField","symbol":"TextChoicesField","correct":"from django_choices_field import TextChoicesField"},{"wrong":"from choices_field import ChoicesField","symbol":"IntegerChoicesFlag","correct":"from django_choices_field import IntegerChoicesFlag"}],"quickstart":{"code":"from django.db import models\nfrom django.utils.translation import gettext_lazy as _\nfrom choices_field import ChoicesField\n\nclass MyModel(models.Model):\n    class Status(models.TextChoices):\n        DRAFT = 'DRAFT', _('Draft')\n        PUBLISHED = 'PUBLISHED', _('Published')\n\n    status = ChoicesField(choices_enum=Status, default=Status.DRAFT)\n\nobj = MyModel(status=MyModel.Status.PUBLISHED)\nprint(obj.status)  # MyModel.Status.PUBLISHED\nprint(obj.status.value)  # 'PUBLISHED'","lang":"python","description":"Define a model with a ChoicesField using Django's TextChoices enum."},"warnings":[{"fix":"Always set null=True when blank=True, or omit blank=True if not needed.","message":"In v4.0.0, passing blank=True without null=True raises ImproperlyConfigured. Previously it was allowed but could cause data integrity issues.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Define a ChoicesEnum subclass and pass it to the choices_enum parameter.","message":"Passing choices as a plain list/tuple in the field constructor is deprecated and will be removed in a future version. Use choices_enum instead.","severity":"deprecated","affected_versions":">=4.0.0"},{"fix":"Upgrade to >=3.1.1, or manually override get_FIELD_display() if stuck on older version.","message":"The 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).","severity":"gotcha","affected_versions":"<3.1.1"},{"fix":"Provide a default argument (e.g., default=MyEnum.FOO) or set null=True and/or blank=True.","message":"ChoicesField 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.","severity":"gotcha","affected_versions":">=4.0.0"}],"env_vars":null,"search_vec":"'/3.9':37 '3.10':28 '3.8':36 '4.0':30 '4.0.0':25 'blank/null':47 'break':41 'chang':42 'check':51 'choic':2,54 'convers':17 'databas':22 'direct':8 'django':1,5,10,29,53 'drop':32 'elimin':15 'enum':13,19,55 'field':3,6,58 'includ':45 'integerchoic':57 'irregular':39 'manual':16 'member':20 'python':27,35 'releas':38 'requir':26 'sets/gets':9 'strict':46 'support':33 'textchoic':56 'textchoices/integerchoices':12 'type':50 'util':52 'v4.0.0':44 'valid':48 'valu':14,23 'version':24","created_at":"2026-05-01T08:08:25.436955+00:00","updated_at":"2026-05-01T08:08:25.436955+00:00","problems":null,"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"4.0.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/bellini666/django-choices-field","docs":"https://django-choices-field.readthedocs.io","changelog":null,"pypi":"https://pypi.org/project/django-choices-field/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["web-framework","database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-07-03","last_verified":"2026-07-03","next_check":"2026-08-02","install_tag":null}}