Skip to main content

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)
```

Project details


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)

Uploaded Source

File details

Details for the file labeled-enum-1.0.2.tar.gz.

File metadata

File hashes

Hashes for labeled-enum-1.0.2.tar.gz
Algorithm Hash digest
SHA256 13981442631ca837c70494130736a519cc6625ac24dacc23efc5c2c75e51c861
MD5 8d7a2e59d23cf1415c1de23c003eb758
BLAKE2b-256 4f9d305448593df44682d1b6ec82919689fe5a8e8439577339e4a91be378e94d

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page