diff --git a/README.rst b/README.rst index 51484ec..c11ad6b 100644 --- a/README.rst +++ b/README.rst @@ -65,7 +65,7 @@ You can use your own labels for Enum items CAT = 1 DOG = 2 - labels = { + _labels = { CAT: 'Cat', DOG: 'Dog' } @@ -112,7 +112,7 @@ The Enum-class can also be used without the EnumField. This is very useful in Dj MALE = 1 FEMALE = 2 - labels = { + _labels = { MALE: 'Male', FEMALE: 'Female', } diff --git a/django_enumfield/enum.py b/django_enumfield/enum.py index eebf6d5..87996c5 100644 --- a/django_enumfield/enum.py +++ b/django_enumfield/enum.py @@ -52,6 +52,15 @@ def __eq__(self, other): def values(self): return self.__members__ + def deconstruct(self): + """ + See "Adding a deconstruct() method" in + https://docs.djangoproject.com/en/1.8/topics/migrations/ + """ + c = self.__class__ + path = '{}.{}'.format(c.__module__, c.__name__) + return path, [self.value], {} + @classmethod def choices(cls, blank=False): """ Choices for Enum @@ -111,7 +120,7 @@ def label(self): :return: label for value :rtype: str or """ - labels = getattr(self.__class__, 'labels', None) + labels = getattr(self.__class__, '_labels', None) if labels is None: return six.text_type(self.name) diff --git a/django_enumfield/tests/models.py b/django_enumfield/tests/models.py index 9cbded3..38c7c96 100644 --- a/django_enumfield/tests/models.py +++ b/django_enumfield/tests/models.py @@ -59,7 +59,7 @@ class LabelBeer(Enum): JUPILER = 1 TYSKIE = 2 - labels = { + _labels = { STELLA: _('Stella Artois'), TYSKIE: _('Browar Tyskie'), }