API

class enums.EAutoChoice

Auto-generated numeric value`s. Thus support sorting by `value.

See also

https
//docs.python.org/3.5/library/enum.html#autonumber
class enums.EChoice

Custom Enum to ease the usage of choices outside the model.

Works by overriding the default _value_ field. This is done to offer a harmonized interface when using auto-generated numeric values. By the way, value is now the actual value to be stored in the DB.

Raises:

AttributeError

in case of duplicated values

See also

http
//stackoverflow.com/a/24105344

Notes

Interface differs slightly from the Enum: EChoice.value returns the actual value to be stored in the DB, while the legacy Enum.value would return the whole tuple used when defining the enumeration item.

classmethod choices()

Generate the choices as required by Django models.

Returns:tuple
classmethod from_value(value)

Return the EChoice object associated with this value, if any.

Parameters:

value

In the type of the value field, as set when instantiating this EChoice.

Returns:

EChoice

Raises:

KeyError

if value does not exist in any element

classmethod get(value, default=None)

Return the EChoice object associated with this value, else default. If default is not given, it defaults to None, so that this method never raises a KeyError.

Parameters:

value

In the type of the value field, as set when instantiating this EChoice.

default

Returned if the value is not found.

Returns:

EChoice

classmethod max_value_length()

Not to be used when using numeric values.

Returns:

int

the maximal length required by this Enum to be stored in the database

classmethod values()
Returns:

tuple

of all the values of this Enum

class enums.EChoiceMeta

Used to override some methods.

See also

https
//blog.ionelmc.ro/2015/02/09/understanding-python-metaclasses/#restrictions-with-multiple-metaclasses

Methods

class enums.EOrderedChoice

Provide ordering of the elements

classmethod choices(order='natural')

Generate the choices as required by Django models.

Parameters:

order : str

in which the elements should be returned. Possible values are: * ‘sorted’, the elements will be sorted by value * ‘reverse’, the elements will be sorted by value as if each comparison were

reversed

  • ‘natural’ (default), the elements are ordered as when instantiated in the enumeration
Returns:

iterable of tuple