mirror of
https://github.com/Hopiu/django-model-utils.git
synced 2026-03-17 04:10:24 +00:00
Get StatusFields working
This commit is contained in:
parent
665fc04b7e
commit
7a33e14f4b
1 changed files with 5 additions and 0 deletions
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Reference in a new issue