Skip to main content

Sanity for the django choices functionality.

Project description

Documentation is a work in progress.

Django choices provides a declarative way of using the choices option on django fields.

Basic Usage

To start you create a choices class in choices.py or const.py (I prefer const.py). Then you point the choices property to the choices attribute of the new class. Django will be able to use the choices and you will be able to access the values by name. For example:

# In choices.py
from djchoices import DjangoChoices, ChoiceItem

class PersonType(DjangoChoices):
    Customer = ChoiceItem("C")
    Employee = ChoiceItem("E")
    Groundhog = ChoiceItem("G")

# In models.py
class Person(models.Model):
    name = models.CharField(max_length=32)
    type = models.CharField(max_length=1, choices=choices.PersonType.choices)

# In other code
Person.create(name="Phil", type=PersonType.Groundhog)

License

Licensed under the MIT License.

Souce Code

The source code can be found on github.

Project details


Download files

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

Files for django-choices, version 1.1.2
Filename, size File type Python version Upload date Hashes
Filename, size django-choices-1.1.2.tar.gz (3.3 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

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