From 826005087541805620be3daffab3e8d106eedc2f Mon Sep 17 00:00:00 2001 From: Jayme Woogerd Date: Wed, 17 Feb 2016 15:16:11 -0800 Subject: [PATCH] Remove SubfieldBase metaclass from EnumFieldMixin Deprecated in Django 1.8, see release notes: https://docs.djangoproject.com/en/1.8/releases/1.8/#subfieldbase fixes #45 --- enumfields/fields.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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()