Added missing deconstruct() methods.
This commit is contained in:
parent
72479a2957
commit
621c25c419
|
@ -15,6 +15,7 @@ from django.db.models.fields.files import FileField, ImageField # NOQA
|
|||
from django.db.models.fields.related import ( # NOQA
|
||||
ForeignKey, ForeignObject, OneToOneField, ManyToManyField,
|
||||
ManyToOneRel, ManyToManyRel, OneToOneRel)
|
||||
from django.db.models.fields.proxy import OrderWrt
|
||||
from django.db.models.deletion import ( # NOQA
|
||||
CASCADE, PROTECT, SET, SET_NULL, SET_DEFAULT, DO_NOTHING, ProtectedError)
|
||||
from django.db.models import signals # NOQA
|
||||
|
|
|
@ -230,6 +230,8 @@ class Field(object):
|
|||
path = path.replace("django.db.models.fields.related", "django.db.models")
|
||||
if path.startswith("django.db.models.fields.files"):
|
||||
path = path.replace("django.db.models.fields.files", "django.db.models")
|
||||
if path.startswith("django.db.models.fields.proxy"):
|
||||
path = path.replace("django.db.models.fields.proxy", "django.db.models")
|
||||
if path.startswith("django.db.models.fields"):
|
||||
path = path.replace("django.db.models.fields", "django.db.models")
|
||||
# Return basic info - other fields should override this.
|
||||
|
|
|
@ -16,3 +16,8 @@ class OrderWrt(fields.IntegerField):
|
|||
kwargs['name'] = '_order'
|
||||
kwargs['editable'] = False
|
||||
super(OrderWrt, self).__init__(*args, **kwargs)
|
||||
|
||||
def deconstruct(self):
|
||||
name, path, args, kwargs = super(OrderWrt, self).deconstruct()
|
||||
del kwargs['editable']
|
||||
return name, path, args, kwargs
|
||||
|
|
|
@ -1019,6 +1019,16 @@ class ForeignObject(RelatedField):
|
|||
|
||||
super(ForeignObject, self).__init__(**kwargs)
|
||||
|
||||
def deconstruct(self):
|
||||
name, path, args, kwargs = super(ForeignObject, self).deconstruct()
|
||||
kwargs['from_fields'] = self.from_fields
|
||||
kwargs['to_fields'] = self.to_fields
|
||||
if isinstance(self.rel.to, six.string_types):
|
||||
kwargs['to'] = self.rel.to
|
||||
else:
|
||||
kwargs['to'] = "%s.%s" % (self.rel.to._meta.app_label, self.rel.to._meta.object_name)
|
||||
return name, path, args, kwargs
|
||||
|
||||
def resolve_related_fields(self):
|
||||
if len(self.from_fields) < 1 or len(self.from_fields) != len(self.to_fields):
|
||||
raise ValueError('Foreign Object from and to fields must be the same non-zero length')
|
||||
|
@ -1243,6 +1253,8 @@ class ForeignKey(ForeignObject):
|
|||
|
||||
def deconstruct(self):
|
||||
name, path, args, kwargs = super(ForeignKey, self).deconstruct()
|
||||
del kwargs['to_fields']
|
||||
del kwargs['from_fields']
|
||||
# Handle the simpler arguments
|
||||
if self.db_index:
|
||||
del kwargs['db_index']
|
||||
|
@ -1255,10 +1267,6 @@ class ForeignKey(ForeignObject):
|
|||
# Rel needs more work.
|
||||
if self.rel.field_name:
|
||||
kwargs['to_field'] = self.rel.field_name
|
||||
if isinstance(self.rel.to, six.string_types):
|
||||
kwargs['to'] = self.rel.to
|
||||
else:
|
||||
kwargs['to'] = "%s.%s" % (self.rel.to._meta.app_label, self.rel.to._meta.object_name)
|
||||
return name, path, args, kwargs
|
||||
|
||||
@property
|
||||
|
|
|
@ -115,6 +115,11 @@ class TeamField(six.with_metaclass(models.SubfieldBase, models.CharField)):
|
|||
def value_to_string(self, obj):
|
||||
return self._get_val_from_obj(obj).to_string()
|
||||
|
||||
def deconstruct(self):
|
||||
name, path, args, kwargs = super(TeamField, self).deconstruct()
|
||||
del kwargs['max_length']
|
||||
return name, path, args, kwargs
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Player(models.Model):
|
||||
|
|
Loading…
Reference in New Issue