Permalink
Browse files

Added missing deconstruct() methods.

  • Loading branch information...
1 parent 72479a2 commit 621c25c419ae0f4d6d0f76725e5f3585d76228d0 @bmispelon bmispelon committed Dec 6, 2013
@@ -15,6 +15,7 @@
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 @@ def deconstruct(self):
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 @@ def __init__(self, *args, **kwargs):
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 @@ def __init__(self, to, from_fields, to_fields, **kwargs):
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 @@ def __init__(self, to, to_field=None, rel_class=ManyToOneRel,
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 @@ def deconstruct(self):
# 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 @@ def to_python(self, value):
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):

0 comments on commit 621c25c

Please sign in to comment.