Skip to content
This repository has been archived by the owner on Mar 30, 2020. It is now read-only.
/ djchoices Public archive

Good choices for Django :)

License

Notifications You must be signed in to change notification settings

orsinium-archive/djchoices

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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'