Skip to content

Instantly share code, notes, and snippets.

@emyller
Created September 14, 2012 04:58
Show Gist options
  • Save emyller/3719892 to your computer and use it in GitHub Desktop.
Save emyller/3719892 to your computer and use it in GitHub Desktop.
# 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