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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: django-choices-field-2.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.8.2 Linux/5.11.0-1021-azure

File hashes

Hashes for django-choices-field-2.0.tar.gz
Algorithm Hash digest
SHA256 46f863b4f12d57f754c39438168860d49787736db1c89cefb9cee972fbfbc5e5
MD5 900701aa075570f447d2671a437e28bf
BLAKE2b-256 f0ca8e51817993d2a1624e86e3e62634e1a4e9e3cf61a77bb778880d34b9c3ec

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_choices_field-2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.8.2 Linux/5.11.0-1021-azure

File hashes

Hashes for django_choices_field-2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a469ae644e60eea5fe1aac68055af5d547d92e05df35aa9cea05196e6eaf5ae8
MD5 cfee4a10e594c802d0be8dd530480dc1
BLAKE2b-256 a2e1de2e558ac55456b17f2a1942b8737c21cc247a9db133d5a70bb35f0602b7

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