mirror of
https://github.com/django/django.git
synced 2025-10-10 02:22:22 +00:00
Fixed #13781 -- Improved select_related in inheritance situations
The select_related code got confused when it needed to travel a reverse relation to a model which had different parent than the originally travelled relation. Thanks to Trac aliases shauncutts for report and ungenio for original patch (committed patch is somewhat modified version of that).
This commit is contained in:
parent
92d7f541da
commit
f51e409a5f
5 changed files with 203 additions and 43 deletions
|
@ -75,6 +75,7 @@ class Options(object):
|
|||
from django.db.backends.util import truncate_name
|
||||
|
||||
cls._meta = self
|
||||
self.model = cls
|
||||
self.installed = re.sub('\.models$', '', cls.__module__) in settings.INSTALLED_APPS
|
||||
# First, construct the default values for these options.
|
||||
self.object_name = cls.__name__
|
||||
|
@ -464,7 +465,7 @@ class Options(object):
|
|||
a granparent or even more distant relation.
|
||||
"""
|
||||
if not self.parents:
|
||||
return
|
||||
return None
|
||||
if model in self.parents:
|
||||
return [model]
|
||||
for parent in self.parents:
|
||||
|
@ -472,8 +473,7 @@ class Options(object):
|
|||
if res:
|
||||
res.insert(0, parent)
|
||||
return res
|
||||
raise TypeError('%r is not an ancestor of this model'
|
||||
% model._meta.module_name)
|
||||
return None
|
||||
|
||||
def get_parent_list(self):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue