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 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
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.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46f863b4f12d57f754c39438168860d49787736db1c89cefb9cee972fbfbc5e5 |
|
MD5 | 900701aa075570f447d2671a437e28bf |
|
BLAKE2b-256 | f0ca8e51817993d2a1624e86e3e62634e1a4e9e3cf61a77bb778880d34b9c3ec |
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | a469ae644e60eea5fe1aac68055af5d547d92e05df35aa9cea05196e6eaf5ae8 |
|
MD5 | cfee4a10e594c802d0be8dd530480dc1 |
|
BLAKE2b-256 | a2e1de2e558ac55456b17f2a1942b8737c21cc247a9db133d5a70bb35f0602b7 |