Skip to main content

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

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=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.4.tar.gz (2.0 kB view details)

Uploaded Source

File details

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

File metadata

File hashes

Hashes for labeled-enum-1.0.4.tar.gz
Algorithm Hash digest
SHA256 fa657e491822f0910892a79b5186250059456a7f5d82f82583376f1d2a490639
MD5 fe10fe3c0f92402d125cbc2dd183384e
BLAKE2b-256 8888f33c346d2da3e182973822c533352a45df0271c1b1005e0fba5e79066047

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