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

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

This version
History Node

1.2.1

History Node

1.2.0

History Node

1.1.0

History Node

1.0.5

History Node

1.0.4

History Node

1.0.3

History Node

1.0.2

History Node

1.0.1

History Node

1.0.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
labeled-enum-1.2.1.tar.gz (2.0 kB) Copy SHA256 hash SHA256 Source None Jul 8, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page