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 TexChoicesField, 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.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file django-choices-field-2.1.tar.gz.

File metadata

  • Download URL: django-choices-field-2.1.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.15 CPython/3.8.2 Linux/5.15.0-1017-azure

File hashes

Hashes for django-choices-field-2.1.tar.gz
Algorithm Hash digest
SHA256 e3e169d8c56992405a72291cac316530a098eec95463bb3b57ba3bb72fcb6de0
MD5 a18983948e55e25d3ac4e63464732ddc
BLAKE2b-256 e0f1d6ddca2679b04a0e39230abf3dc557369d5f23d00e8a95813fb2edfc1997

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_choices_field-2.1-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.15 CPython/3.8.2 Linux/5.15.0-1017-azure

File hashes

Hashes for django_choices_field-2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 57be7202b51c105de522b9fec7831a1d5916df4c1e3aa344f1a10882d335d0ac
MD5 f59b9441ce263698c62a7ce142f00e6d
BLAKE2b-256 7432652b8a7e4c57fc67acfb6d18ee69cf761c3a8ab62a38377fb67766eaca01

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