Skip to main content

Sanity for the django choices functionality.

Project description

============================
Django-Choices
============================
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_
fields.

-----------
Installation
-----------
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 const.py 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 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_.

.. _choices: http://docs.djangoproject.com/en/1.2/ref/models/fields/#choices
.. _MIT License: http://en.wikipedia.org/wiki/MIT_License
.. _django: http://www.djangoproject.com/
.. _github: https://github.com/bigjason/django-choices
.. _PyPi: http://pypi.python.org/pypi/django-choices/

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

Uploaded Source

File details

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

File metadata

File hashes

Hashes for django-choices-1.1.6.tar.gz
Algorithm Hash digest
SHA256 1e7b9c6fa378bcd004106bd8e95a28aff4a8ac08760f8ecc4dbccfa970f550e0
MD5 009a3e4261ee260e86650339bd6e7e8b
BLAKE2b-256 f889f88b84ec2464a3d65b451274e2aacd2b9eeb6dda2b330a9158f155abaf1e

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