Django field that set/get django's new TextChoices/IntegerChoices enum.
Project description
django-choices-field
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 TextChoicesField, 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django_choices_field-2.1.1.tar.gz
.
File metadata
- Download URL: django_choices_field-2.1.1.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.8.2 Linux/5.15.0-1035-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e28f83d65cbb52b2736faf7219ca049d21d5a15c5918e4d071c60409fc7fe21 |
|
MD5 | 5e26930f15bd97c0ca7dbecddc14b394 |
|
BLAKE2b-256 | 93be12ee6d9036349b3f5de295de71a3a416a0bb1723498d150b862bb06effed |
File details
Details for the file django_choices_field-2.1.1-py3-none-any.whl
.
File metadata
- Download URL: django_choices_field-2.1.1-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.8.2 Linux/5.15.0-1035-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 431f228192340322b5e9a705bf1cd67c995596a7da5d5a868b25e48bafc07e4b |
|
MD5 | 2e1757ee8b077b1e0c17ee43ab8f129c |
|
BLAKE2b-256 | 989dd6bed9cd7b55760d78790a6c287eb5b92aec627b80fc89ad369f3f4dff10 |