Django friendly, iterable Enum type with labels.
Project description
A Django-friendly iterable Enum type with labels.
Example
>>> from lenum import LabeledEnum
>>> class STATE_CHOICES(LabeledEnum):
... NEW = 0
... IN_PROGRESS = 1
... REVIEW = 2, 'In Review'
...
>>>
>>> STATE_CHOICES.NEW
0
>>> STATE_CHOICES.IN_PROGRESS
1
>>> STATE_CHOICES[2]
'In Review'
>>> list(STATE_CHOICES)
[(0, 'New'), (1, 'In Progress'), (2, 'In Review')]
>>> STATE_CHOICES.for_label('In Progress')
1
```
>>> STATE_CHOICES.names
('NEW', 'IN_PROGRESS', 'REVIEW')
Usage in Django:
class MyModel(models.Model):
class STATUS(LabeledEnum):
CLOSED = 0
NEW = 1
PENDING = 2, 'Process Pending'
FAILED = -1, 'Processing Failed'
status = models.IntegerField(choices=STATUS, default=STATUS.NEW)
Installation
pip install labeled-enum
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
labeled-enum-1.2.0.tar.gz
(2.0 kB
view details)
File details
Details for the file labeled-enum-1.2.0.tar.gz
.
File metadata
- Download URL: labeled-enum-1.2.0.tar.gz
- Upload date:
- Size: 2.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 853489318cf087827e292dc4b9fd063a14b5f6994c38fca5093c292113c42b9a |
|
MD5 | 88edcca4c6ee795292246d25814f83e4 |
|
BLAKE2b-256 | f998d3ac0cad469604e3068945f2a350a518e05d37839d95d58ff2cefc336bc2 |