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.

Source Distribution

django-choices-1.1.2.tar.gz (3.3 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