diff --git a/enumfields/fields.py b/enumfields/fields.py index 5c2558f..8d5b342 100644 --- a/enumfields/fields.py +++ b/enumfields/fields.py @@ -9,7 +9,9 @@ from .compat import import_string -class EnumFieldMixin(six.with_metaclass(models.SubfieldBase)): +metaclass = models.SubfieldBase if django.VERSION < (1, 8) else type + +class EnumFieldMixin(six.with_metaclass(metaclass)): def __init__(self, enum, **options): if isinstance(enum, six.string_types): self.enum = import_string(enum) @@ -34,6 +36,9 @@ def to_python(self, value): def get_prep_value(self, value): return None if value is None else self.enum(value).value + def from_db_value(self, value, expression, connection, context): + return self.to_python(value) + def value_to_string(self, obj): """ This method is needed to support proper serialization. While its name is value_to_string()