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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: django-choices-field-1.3.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-1.3.tar.gz
Algorithm Hash digest
SHA256 0df4a82c301b015a6bc7b440d424562f84bd25fa132ffd18ee981f63a3db2468
MD5 cac7a69615049532c4318dc37de28db6
BLAKE2b-256 802e70c400dd463cb243c0a23ed91b5317a89ab3fd17ba778f20490471055a9d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_choices_field-1.3-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-1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 cde3d3bdf93d2caa07cba533a1a29529f49b215a964914def95e8de36e75c510
MD5 f2272b3c0e7ce50c74ecd185ebc8de67
BLAKE2b-256 23d9a3c0fcfd3d1dd37b8f47f54da64b92e5707b074159db617f87767cb403e1

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