Django friendly, iterable Enum type with labels.
Project description
# labeled-enums
A Django-friendly iterable Enum type with labels.
# Example
```python
>>> class STATE_CHOICES(Choices):
... 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')]
```
Usage in Django:
```python
class MyModel(models.Model):
class STATUS(Choices):
CLOSED = 0
NEW = 1
PENDING = 2, 'Process Pending'
FAILED = -1, 'Processing Failed'
status = models.IntegerField(choices=list(STATUS), default=STATUS.NEW)
```
A Django-friendly iterable Enum type with labels.
# Example
```python
>>> class STATE_CHOICES(Choices):
... 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')]
```
Usage in Django:
```python
class MyModel(models.Model):
class STATUS(Choices):
CLOSED = 0
NEW = 1
PENDING = 2, 'Process Pending'
FAILED = -1, 'Processing Failed'
status = models.IntegerField(choices=list(STATUS), default=STATUS.NEW)
```
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.0.2.tar.gz
(1.7 kB
view details)
File details
Details for the file labeled-enum-1.0.2.tar.gz
.
File metadata
- Download URL: labeled-enum-1.0.2.tar.gz
- Upload date:
- Size: 1.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13981442631ca837c70494130736a519cc6625ac24dacc23efc5c2c75e51c861 |
|
MD5 | 8d7a2e59d23cf1415c1de23c003eb758 |
|
BLAKE2b-256 | 4f9d305448593df44682d1b6ec82919689fe5a8e8439577339e4a91be378e94d |