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:
Anssi Kääriäinen 2012-11-09 20:21:46 +02:00
parent 92d7f541da
commit f51e409a5f
5 changed files with 203 additions and 43 deletions

View file

@ -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):
"""