Skip to main content

Django friendly, iterable Enum type with labels.

Project description

A Django-friendly iterable Enum type with labels.

Example

>>> 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:

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.3.tar.gz (1.9 kB view hashes)

Uploaded Source

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