Skip to content

Commit

Permalink
Remove SubfieldBase metaclass from EnumFieldMixin
Browse files Browse the repository at this point in the history
Deprecated in Django 1.8, see release notes:
https://docs.djangoproject.com/en/1.8/releases/1.8/#subfieldbase

fixes hzdg#45
  • Loading branch information
Jayme Woogerd committed Feb 26, 2016
1 parent 336f30e commit 8260050
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion enumfields/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down

0 comments on commit 8260050

Please sign in to comment.