Get StatusFields working

This commit is contained in:
jarekwg 2015-10-29 00:02:46 +11:00
parent 665fc04b7e
commit 7a33e14f4b

View file

@ -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):