Moved common code to RelatedField.deconstruct().

This commit is contained in:
Adam Bogdał 2017-06-14 08:36:07 -04:00 committed by Tim Graham
parent bd0c9388c0
commit 9f4e0fde0a
1 changed files with 4 additions and 8 deletions

View File

@ -322,6 +322,10 @@ class RelatedField(Field):
name, path, args, kwargs = super().deconstruct() name, path, args, kwargs = super().deconstruct()
if self.remote_field.limit_choices_to: if self.remote_field.limit_choices_to:
kwargs['limit_choices_to'] = self.remote_field.limit_choices_to kwargs['limit_choices_to'] = self.remote_field.limit_choices_to
if self.remote_field.related_name is not None:
kwargs['related_name'] = self.remote_field.related_name
if self.remote_field.related_query_name is not None:
kwargs['related_query_name'] = self.remote_field.related_query_name
return name, path, args, kwargs return name, path, args, kwargs
def get_forward_related_filter(self, obj): def get_forward_related_filter(self, obj):
@ -561,10 +565,6 @@ class ForeignObject(RelatedField):
kwargs['from_fields'] = self.from_fields kwargs['from_fields'] = self.from_fields
kwargs['to_fields'] = self.to_fields kwargs['to_fields'] = self.to_fields
if self.remote_field.related_name is not None:
kwargs['related_name'] = self.remote_field.related_name
if self.remote_field.related_query_name is not None:
kwargs['related_query_name'] = self.remote_field.related_query_name
if self.remote_field.parent_link: if self.remote_field.parent_link:
kwargs['parent_link'] = self.remote_field.parent_link kwargs['parent_link'] = self.remote_field.parent_link
# Work out string form of "to" # Work out string form of "to"
@ -1395,10 +1395,6 @@ class ManyToManyField(RelatedField):
kwargs['db_table'] = self.db_table kwargs['db_table'] = self.db_table
if self.remote_field.db_constraint is not True: if self.remote_field.db_constraint is not True:
kwargs['db_constraint'] = self.remote_field.db_constraint kwargs['db_constraint'] = self.remote_field.db_constraint
if self.remote_field.related_name is not None:
kwargs['related_name'] = self.remote_field.related_name
if self.remote_field.related_query_name is not None:
kwargs['related_query_name'] = self.remote_field.related_query_name
# Rel needs more work. # Rel needs more work.
if isinstance(self.remote_field.model, str): if isinstance(self.remote_field.model, str):
kwargs['to'] = self.remote_field.model kwargs['to'] = self.remote_field.model