1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #26186 -- Documented how app relative relationships of abstract models behave.

This partially reverts commit bc7d201bdb.

Thanks Tim for the review.

Refs #25858.
This commit is contained in:
Simon Charette
2016-02-22 16:05:47 -05:00
parent eac1423f9e
commit 0223e213dd
4 changed files with 71 additions and 36 deletions

View File

@@ -35,7 +35,7 @@ from .reverse_related import (
RECURSIVE_RELATIONSHIP_CONSTANT = 'self'
def resolve_relation(scope_model, relation, resolve_recursive_relationship=True):
def resolve_relation(scope_model, relation):
"""
Transform relation into a model or fully-qualified model string of the form
"app_label.ModelName", relative to scope_model.
@@ -50,11 +50,12 @@ def resolve_relation(scope_model, relation, resolve_recursive_relationship=True)
"""
# Check for recursive relations
if relation == RECURSIVE_RELATIONSHIP_CONSTANT:
if resolve_recursive_relationship:
relation = scope_model
relation = scope_model
# Look for an "app.Model" relation
elif isinstance(relation, six.string_types) and '.' not in relation:
relation = "%s.%s" % (scope_model._meta.app_label, relation)
if isinstance(relation, six.string_types):
if "." not in relation:
relation = "%s.%s" % (scope_model._meta.app_label, relation)
return relation
@@ -312,11 +313,6 @@ class RelatedField(Field):
field.remote_field.model = related
field.do_related_class(related, model)
lazy_related_operation(resolve_related_class, cls, self.remote_field.model, field=self)
else:
# Bind a lazy reference to the app in which the model is defined.
self.remote_field.model = resolve_relation(
cls, self.remote_field.model, resolve_recursive_relationship=False
)
def get_forward_related_filter(self, obj):
"""
@@ -1565,11 +1561,6 @@ class ManyToManyField(RelatedField):
lazy_related_operation(resolve_through_model, cls, self.remote_field.through, field=self)
elif not cls._meta.swapped:
self.remote_field.through = create_many_to_many_intermediary_model(self, cls)
else:
# Bind a lazy reference to the app in which the model is defined.
self.remote_field.through = resolve_relation(
cls, self.remote_field.through, resolve_recursive_relationship=False
)
# Add the descriptor for the m2m relation.
setattr(cls, self.name, ManyToManyDescriptor(self.remote_field, reverse=False))