Skip to content

Instantly share code, notes, and snippets.

@minism
Created January 7, 2013 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minism/4473178 to your computer and use it in GitHub Desktop.
Save minism/4473178 to your computer and use it in GitHub Desktop.
# Standard django choices style
CHOICE_APPLE = 'apple'
CHOICE_BANANA = 'banana'
CHOICE_ORANGE = 'orange'
FRUIT_CHOICES = (
(CHOICE_APPLE, 'Apple'),
(CHOICE_BANANA, 'Banana'),
(CHOICE_ORANGE, 'Orange'),
)
fruit_field = models.CharField(choices=FRUIT_CHOICES, default=CHOICE_APPLE)
# Syntax I would prefer
class Fruit(ChoiceEnum):
APPLE = 'apple'
BANANA = 'banana'
ORANGE = 'orange'
fruit_field = models.CharField(choices=Fruit.as_choices(), default=Fruit.APPLE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment