Skip to main content

Sanity for the django choices functionality.

Project description

Order and sanity for django model choices.
*Documentation is a work in progress.*

Django choices provides a declarative way of using the choices_ option on django_

You can install via PyPi_ or direct from the github_ repo.

To install with pip::

$ pip install django-choices

To install with easy_install::

$ easy_install django-choices

Basic Usage
To start you create a choices class somewhere. I use but you can just do
it right on the model if you prefer. 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
from djchoices import DjangoChoices, ChoiceItem

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

# In
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)

Licensed under the `MIT License`_.

Souce Code
The source code can be found on github_.

.. _choices:
.. _MIT License:
.. _django:
.. _github:
.. _PyPi:

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.6
Filename, size File type Python version Upload date Hashes
Filename, size django-choices-1.1.6.tar.gz (3.7 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