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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: django-choices-field-1.2.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.8.2 Linux/5.8.0-1042-azure

File hashes

Hashes for django-choices-field-1.2.tar.gz
Algorithm Hash digest
SHA256 924eb3ea770fe9c34cca98520805ec60b166eba9f2deac60f0e898f736849733
MD5 0bec3a95c815e93e192d7a69bf33cc7e
BLAKE2b-256 d63e0ffe620b963a4e69fdfd92622a718c7e66bd01f150eb6c5be81f81e03ad1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_choices_field-1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4bca6740e5a1755975b750a71e73bbaed9722da90e47a7f877a802e5bfc40031
MD5 307ea65acabab34be1e043dc4645b4e3
BLAKE2b-256 d35b7e6747416f304fd53d52f5708b13855cccb39ed7806c4c011044f51c9de9

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