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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for django-choices-field-1.1.tar.gz
Algorithm Hash digest
SHA256 89fc712d89096115a0ae470d7a97ad95cfcb06b2e9fe5378f7ca81fc016b8a81
MD5 31b264669683fcb13a2f8bf45bedd102
BLAKE2b-256 54cd649cb645f77d75142828fa450bd0fdae66165f2e1f40bb60b6b0adfc867d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_choices_field-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b31f62998b55e8b4d13aeb4211094e1cc33a46cf67c43bc9356d11ed9ff7a4bb
MD5 9e61303edc44691e68cbc5346393de56
BLAKE2b-256 b5b30b72dc49a76f1d67e1bb4139ef7aa20e40e68d5ee8e872ec1dc6e0a859f2

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