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.0.tar.gz (3.1 kB view details)

Uploaded Source

File details

Details for the file django-choices-1.1.0.tar.gz.

File metadata

File hashes

Hashes for django-choices-1.1.0.tar.gz
Algorithm Hash digest
SHA256 7ff424a67fb69cfa109dab2977e7ef8ef4e6952b3436ae79c52cac464cb0f257
MD5 412ad559b06ceeb3457f3c77629c338d
BLAKE2b-256 b42cdf92a187563b3bb29f92771985e7faac247513bc8c1fc361d36ab9730432

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page