===================
django-choices-enum allows the usage of the 2.x backport of Python 3.4's enum
package (enum34) as choices in Django models.
from django.db import models
from django_choices_enum import ChoicesEnum
class Monster(models.Model):
class Types(str, ChoicesEnum):
BEAST = ('beast', 'Beast')
UNDEAD = ('undead', 'Undead')
HUMAN = ('human', 'Human')
name = models.CharField(max_length=40)
type = models.CharField(max_length=40, choices=Types.choices())
You may now write code like this:
monsters = Monster.objects.filter(type=Monster.Types.BEAST)
for m in monsters:
assert m.type == Monster.Types.BEAST
m = Monster(name='Vampire', type=Monster.Types.UNDEAD)
m.save()
Details
=======
Each enumeration is a class subclassed from the type of the field and the
ChoicesEnum type:
class MyIntEnumeration(int, ChoicesEnum):
A = (1, 'Label A')
Each constant is then assigned a tuple of (value, label) as expected by
the Django choices parameter. If the constant and label are the same,
you may omit the tuple and simply set the constant equal to the value of
the choice.
Contributions
=============
I did not really write most of this code. It was found and fixed from
a Gist:
https://gist.github.com/dstufft/5600529
Metadata
Release files for django-choices-enum 0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-choices-enum-0.2.tar.gz | 3.8 kB | Without provenance | Details for django-choices-enum-0.2.tar.gz |
Release files / django-choices-enum-0.2.tar.gz
| Download URL | django-choices-enum-0.2.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5ad88f4bdb03b2f7af4ab1352f37d4b63adb350965961de2d57c39d53ae0ab85
|
|
BLAKE2b-256 checksum How to use checksums |
585c61f4a751fbc78424e97b93f69b8ccd92bb71077f15c23bf4709efba32833
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-choices-enum 0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.