This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Sanity for the django choices functionality.

Project Description

Order and sanity for django model choices.

Django choices provides a declarative way of using the choices option on django fields. Read the full documentation on ReadTheDocs.

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. Then you point the choices property on your fields 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 you can replace this:

# In models.py
class Person(models.Model):
    # Choices
    PERSON_TYPE = (
        ("C", "Customer"),
        ("E", "Employee"),
        ("G", "Groundhog"),
    )
    # Fields
    name = models.CharField(max_length=32)
    type = models.CharField(max_length=1, choices=PERSON_TYPE)

With this:

# In models.py
from djchoices import DjangoChoices, ChoiceItem

class Person(models.Model):
    # Choices
    class PersonType(DjangoChoices):
        customer = ChoiceItem("C")
        employee = ChoiceItem("E")
        groundhog = ChoiceItem("G")

    # Fields
    name = models.CharField(max_length=32)
    type = models.CharField(max_length=1, choices=PersonType.choices)

You can use this elsewhere like this:

# Other code
Person.create(name="Phil", type=Person.PersonType.groundhog)

You can use them without value, and the label will be used as value:

class Sample(DjangoChoices):
    option_a = ChoiceItem()
    option_b = ChoiceItem()

print(Sample.option_a)  # "option_a"

License

Licensed under the MIT License.

Souce Code

The source code can be found on github.

Release History

Release History

This version
History Node

1.6.0

History Node

1.5.1

History Node

1.5.0

History Node

1.4.4

History Node

1.4.3

History Node

1.4.2

History Node

1.4

History Node

1.3

History Node

1.2

History Node

1.1.12

History Node

1.1.11

History Node

1.1.9

History Node

1.1.8

History Node

1.1.7

History Node

1.1.6

History Node

1.1.2

History Node

1.1.1

History Node

1.1.0

History Node

1.0.5

History Node

1.0.0

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django_choices-1.6.0-py2.py3-none-any.whl (8.9 kB) Copy SHA256 Checksum SHA256 3.6 Wheel Jul 12, 2017
django-choices-1.6.0.tar.gz (6.3 kB) Copy SHA256 Checksum SHA256 Source Jul 12, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting