Good choices for Django :)
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
djchoices
.gitignore
LICENSE
README.md
deploy.sh
setup.cfg
setup.py

README.md

Django app for choices with autocomplete and good readability

Installation

For python<=3.4 install enum34:

sudo pip install enum34

Install this module:

sudo pip install -e git+https://github.com/orsinium/djchoices.git#egg=djchoices

Example

Definition:

from djchoices import Choices

class SOURCES(Choices):
    IOS = 'i', 'iOS app'
    ANDROID = 'a', 'Android app'

Usage in models:

source = models.CharField(max_length=1, choices=SOURCES.choices())

Manual usage:

SOURCES.choices()
# (('a', 'Android app'), ('i', 'iOS app'))

SOURCES.IOS
# <SOURCES.IOS: ('i', 'iOS app')>

SOURCES.IOS.verbose
# 'iOS app'

SOURCES.IOS.db
# 'i'

SOURCES.IOS.name
# 'IOS'

SOURCES.IOS.value
# ('i', 'iOS app')

SOURCES.by_db('i')
# <SOURCES.IOS: ('i', 'iOS app')>

SOURCES.by_verbose('iOS app')
# <SOURCES.IOS: ('i', 'iOS app')>

SOURCES.verbose_by_db('i')
# 'iOS app'

SOURCES.db_by_verbose('iOS app')
# 'i'