Skip to content

Instantly share code, notes, and snippets.

@tadeo
tadeo / choices_enum.py
Last active August 6, 2024 01:25 — forked from treyhunner/choice_enum.py
Enum for use with Django ChoiceField
from enum import Enum, EnumMeta
class ChoicesEnumMeta(EnumMeta):
def __iter__(self):
return ((choice.name, choice.value) for choice in super().__iter__())
class ChoicesEnum(Enum, metaclass=ChoicesEnumMeta):
def __str__(self):