Skip to main content

Django field that set/get django's new TextChoices/IntegerChoices enum.

Project description

django-choices-field

build status coverage PyPI version python version django version

Django field that set/get django's new TextChoices/IntegerChoices enum.

Install

pip install django-choices-field

Usage

from django.db import models
from django_choices_field import TextChoicesField, IntegerChoicesField


class MyModel(models.Model):
    class TextEnum(models.TextChoices):
        FOO = "foo", "Foo Description"
        BAR = "bar", "Bar Description"

    class IntegerEnum(models.IntegerChoices):
        FIRST = 1, "First Description"
        SECOND = 2, "Second Description"

    c_field = TextChoicesField(
        choices_enum=TextEnum,
        default=TextEnum.FOO,
    )
    i_field = IntegerChoicesField(
        choices_enum=IntegerEnum,
        default=IntegerEnum.FIRST,
    )


obj = MyModel()
obj.c_field  # MyModel.TextEnum.FOO
isinstance(obj.c_field, MyModel.TextEnum) # True
obj.i_field  # MyModel.IntegerEnum.FIRST
isinstance(obj.i_field, MyModel.IntegerEnum) # True

License

This project is licensed under MIT licence (see LICENSE for more info)

Contributing

Make sure to have poetry installed.

Install dependencies with:

poetry install

Run the testsuite with:

poetry run pytest

Feel free to fork the project and send me pull requests with new features, corrections and translations. I'll gladly merge them and release new versions ASAP.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_choices_field-2.1.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

django_choices_field-2.1.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file django_choices_field-2.1.1.tar.gz.

File metadata

  • Download URL: django_choices_field-2.1.1.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.8.2 Linux/5.15.0-1035-azure

File hashes

Hashes for django_choices_field-2.1.1.tar.gz
Algorithm Hash digest
SHA256 5e28f83d65cbb52b2736faf7219ca049d21d5a15c5918e4d071c60409fc7fe21
MD5 5e26930f15bd97c0ca7dbecddc14b394
BLAKE2b-256 93be12ee6d9036349b3f5de295de71a3a416a0bb1723498d150b862bb06effed

See more details on using hashes here.

File details

Details for the file django_choices_field-2.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_choices_field-2.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 431f228192340322b5e9a705bf1cd67c995596a7da5d5a868b25e48bafc07e4b
MD5 2e1757ee8b077b1e0c17ee43ab8f129c
BLAKE2b-256 989dd6bed9cd7b55760d78790a6c287eb5b92aec627b80fc89ad369f3f4dff10

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page