From 9f4e0fde0a25ae0c21359f5194435aaf5ca341c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Bogda=C5=82?= Date: Wed, 14 Jun 2017 08:36:07 -0400 Subject: [PATCH] Moved common code to RelatedField.deconstruct(). --- django/db/models/fields/related.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index b01142f056..e92eca8fb4 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -322,6 +322,10 @@ class RelatedField(Field): name, path, args, kwargs = super().deconstruct() if 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 def get_forward_related_filter(self, obj): @@ -561,10 +565,6 @@ class ForeignObject(RelatedField): kwargs['from_fields'] = self.from_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: kwargs['parent_link'] = self.remote_field.parent_link # Work out string form of "to" @@ -1395,10 +1395,6 @@ class ManyToManyField(RelatedField): kwargs['db_table'] = self.db_table if self.remote_field.db_constraint is not True: 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. if isinstance(self.remote_field.model, str): kwargs['to'] = self.remote_field.model