Skip to content

Instantly share code, notes, and snippets.

@dmitryTsatsarin
Last active August 29, 2015 14:24
Show Gist options
  • Save dmitryTsatsarin/76b58a3cbd6c3c7dbf55 to your computer and use it in GitHub Desktop.
Save dmitryTsatsarin/76b58a3cbd6c3c7dbf55 to your computer and use it in GitHub Desktop.
Extendent django choice. You can access by name like a dictionary
__author__ = 'dmitry'
class StatesCreator(object):
def __init__(self, states_dict):
self.states_dict = states_dict
def for_choice(self):
return tuple(zip(self.states_dict.values(), self.states_dict.keys()))
def __getitem__(self, key):
return self.states_dict[key]
SERVICE_STATES = StatesCreator(
{
'New': 0,
'Approved': 1,
'Declined': 2,
}
)
print(SERVICE_STATES.for_choice())
print(SERVICE_STATES['Approved'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment