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.2.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

django_choices_field-2.1.2-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_choices_field-2.1.2.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-1037-azure

File hashes

Hashes for django_choices_field-2.1.2.tar.gz
Algorithm Hash digest
SHA256 1fd3625c7fc8277c005a5a91f2abdc6f8dc2aa9a1c5a16ff3efe6b8693cb04f1
MD5 e00a413d61386c95ea5b939f1b538335
BLAKE2b-256 2d221eab01af1ee117b38cbfe7549c2a5b3f11d969889dd6720235645d04dfba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_choices_field-2.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bec673ba0d432d59033aca0099a356239360c740c8585a1ecb4ed4db046ce616
MD5 8a05ffc8b5024d6a4a1681202e803fa4
BLAKE2b-256 4542d96f05265328175e74d677f4b123e25efa05169bc839b9d28a5c0d9fe4f6

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