Enum classes¶
-
class
enumchoicefield.enum.
PrettyEnum
¶ A
PrettyEnum
makes defining nice, human-readable names for enum members easy. To use it, subclassPrettyEnum
and declare the enum members with their human-readable name as their value:class Fruit(PrettyEnum): apple = "Apple" banana = "Banana" orange = "Orange"
The members’ values will be automatically set to ascending integers, starting at one. In the example above,
Fruit.apple.value
is1
, andFruit.orange.value
is3
.
-
class
enumchoicefield.enum.
DeconstructableEnum
¶ -
deconstruct
()¶ a
DeconstructableEnum
definesdeconstruct()
, compatible with Django migrations. If you want to set a default for anEnumChoiceField
, the enum must be deconstructable.
-
-
class
enumchoicefield.enum.
ChoiceEnum
¶ a
ChoiceEnum
extends bothPrettyEnum
andDeconstructableEnum
. It is recommended to use aChoiceEnum
subclass withEnumChoiceField
, but this is not required.