{"id":3965,"library":"django-choices","title":"django-choices","description":"Django-choices provides a declarative way of using the `choices` option on Django fields, aiming to add order and sanity to Django model choices. The current version is 2.0.0. While it served a valuable purpose, the library is now in maintenance mode, with its maintainers strongly recommending migration to native Django 3.0+ `TextChoices` or `IntegerChoices` for new projects due to Django's improved built-in functionality.","status":"maintenance","version":"2.0.0","language":"en","source_language":"en","source_url":"https://github.com/bigjason/django-choices","tags":["django","choices","enums","model-fields","deprecated"],"install":[{"cmd":"pip install django-choices","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Core framework dependency; tested against Django 3.2+.","package":"Django","optional":false}],"imports":[{"symbol":"DjangoChoices","correct":"from djchoices import DjangoChoices"},{"note":"The primary import path is `djchoices`, not `django_choices`.","wrong":"from django_choices import ChoiceItem","symbol":"ChoiceItem","correct":"from djchoices import ChoiceItem"},{"note":"C is an alias for ChoiceItem for brevity.","symbol":"C","correct":"from djchoices import C"}],"quickstart":{"code":"import os\nimport django\nfrom django.conf import settings\nfrom django.db import models\n\n# Minimal Django settings for standalone script\nsettings.configure(\n    INSTALLED_APPS=['test_app'],\n    DATABASES={'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': ':memory:'}},\n    USE_I18N=True, # Required for ugettext_lazy if used in ChoiceItem\n)\ndjango.setup()\n\nfrom djchoices import ChoiceItem, DjangoChoices\n\nclass Author(models.Model):\n    name = models.CharField(max_length=100)\n\n    def __str__(self):\n        return self.name\n\nclass Book(models.Model):\n    class BookType(DjangoChoices):\n        short_story = ChoiceItem('short', 'Short story')\n        novel = ChoiceItem('novel', 'Novel')\n        non_fiction = ChoiceItem('non_fiction', 'Non fiction')\n\n    author = models.ForeignKey(Author, on_delete=models.CASCADE)\n    book_type = models.CharField(\n        max_length=20,\n        choices=BookType.choices,\n        default=BookType.novel\n    )\n\n    def __str__(self):\n        return f\"{self.book_type.label} by {self.author.name}\"\n\n\n# Example usage (requires an actual Django project setup normally)\nif __name__ == '__main__':\n    # This part would typically be in your Django ORM interaction code\n    # For this example, we'll just demonstrate the choice access.\n    print(f\"Book type choices: {Book.BookType.choices}\")\n    print(f\"Default book type value: {Book.BookType.novel.value}\")\n    print(f\"Default book type label: {Book.BookType.novel.label}\")\n\n    # In a real Django setup, you would create and query model instances.\n    # Example of accessing choices directly:\n    status_options = []\n    for value, label in Book.BookType.choices:\n        status_options.append(f\"Value: {value}, Label: {label}\")\n    print(\"\\nAvailable Book Types:\")\n    for option in status_options:\n        print(option)\n","lang":"python","description":"Define choice sets using `DjangoChoices` and `ChoiceItem` classes, then integrate them into Django model fields. The `choices` attribute of your `DjangoChoices` class provides the iterable required by Django model fields."},"warnings":[{"fix":"For new projects or when refactoring, use `django.db.models.TextChoices` or `django.db.models.IntegerChoices`. Consult Django's official documentation for usage patterns.","message":"The `django-choices` library is no longer actively developed, and its use is strongly discouraged for new projects. Django 3.0+ introduced native enumeration types (`TextChoices`, `IntegerChoices`) that largely supersede the functionality provided by this package.","severity":"deprecated","affected_versions":"2.0.0 and earlier"},{"fix":"Always verify the PyPI project page and GitHub repository (`https://github.com/bigjason/django-choices`) to confirm you're using the intended library. The correct import path is `from djchoices import ...`.","message":"There are several similarly named packages (e.g., `django-choices-field`, `django-js-choices`) that serve different purposes. Ensure you are installing and importing from the correct `django-choices` library by `bigjason`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your import statements use `from djchoices import ChoiceItem, DjangoChoices`.","message":"The module to import from is `djchoices`, not `django_choices` or `django.choices`. This is a common point of confusion.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}