Created
September 14, 2012 04:58
-
-
Save emyller/3719892 to your computer and use it in GitHub Desktop.
This file contains 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
# encoding: utf-8 | |
class choices(list): | |
''' | |
makes an enumerated list of tuples in the format accepted by | |
Django model fields' 'choices' option. | |
>>> colors = choices( | |
('RED', '#f00', 'Normal red'), | |
('BLUE', '#00f', 'Blue'), | |
) | |
>>> colors[0] | |
('#f00', 'Normal red') | |
>>> colors.RED | |
'#f00' | |
''' | |
def __init__(self, iterable): | |
if iterable: | |
for item in iterable: | |
(attr_name, value, label) = item | |
setattr(self, attr_name, value) | |
self.append((value, label)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment