diff --git a/model_utils/fields.py b/model_utils/fields.py index 74c44b2..805c707 100644 --- a/model_utils/fields.py +++ b/model_utils/fields.py @@ -1,5 +1,6 @@ from __future__ import unicode_literals +import django from django.db import models from django.conf import settings from django.utils.encoding import python_2_unicode_compatible @@ -59,6 +60,8 @@ class StatusField(models.CharField): "To use StatusField, the model '%s' must have a %s choices class attribute." \ % (sender.__name__, self.choices_name) self._choices = getattr(sender, self.choices_name) + if django.VERSION >= (1, 9, 0): + self.choices = self._choices if not self.has_default(): self.default = tuple(getattr(sender, self.choices_name))[0][0] # set first as default @@ -68,6 +71,8 @@ class StatusField(models.CharField): # the STATUS class attr being available), but we need to set some dummy # choices now so the super method will add the get_FOO_display method self._choices = [(0, 'dummy')] + if django.VERSION >= (1, 9, 0): + self.choices = self._choices super(StatusField, self).contribute_to_class(cls, name) def deconstruct(self):