Skip to content

Commit 8260050

Browse files
author
Jayme Woogerd
committed
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
1 parent 336f30e commit 8260050

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

enumfields/fields.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
from .compat import import_string
1111

12-
class EnumFieldMixin(six.with_metaclass(models.SubfieldBase)):
12+
metaclass = models.SubfieldBase if django.VERSION < (1, 8) else type
13+
14+
class EnumFieldMixin(six.with_metaclass(metaclass)):
1315
def __init__(self, enum, **options):
1416
if isinstance(enum, six.string_types):
1517
self.enum = import_string(enum)
@@ -34,6 +36,9 @@ def to_python(self, value):
3436
def get_prep_value(self, value):
3537
return None if value is None else self.enum(value).value
3638

39+
def from_db_value(self, value, expression, connection, context):
40+
return self.to_python(value)
41+
3742
def value_to_string(self, obj):
3843
"""
3944
This method is needed to support proper serialization. While its name is value_to_string()

0 commit comments

Comments
 (0)