Last active
August 29, 2015 14:24
-
-
Save dmitryTsatsarin/76b58a3cbd6c3c7dbf55 to your computer and use it in GitHub Desktop.
Extendent django choice. You can access by name like a dictionary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__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