Skip to content

Instantly share code, notes, and snippets.

@hirokiky
Last active October 26, 2016 04:51
Show Gist options
  • Save hirokiky/a73535e37e555bed3301bcbe938f38cb to your computer and use it in GitHub Desktop.
Save hirokiky/a73535e37e555bed3301bcbe938f38cb to your computer and use it in GitHub Desktop.
A Base Enum class which can be used for Django's choices field.
class ChoicesEnum(Enum):
def __str__(self):
return self.value
@classmethod
def choices(cls):
return tuple(
(item.value, item.name.replace('_', ' ').title()) for item in cls
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment