Factored out a semi-complex if-test that was used in two places.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@7782 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2008-06-29 09:40:17 +00:00
parent a8fa3fd81f
commit 5326cd293e
3 changed files with 22 additions and 6 deletions

View file

@ -48,3 +48,20 @@ class Q(tree.Node):
obj.negate()
return obj
def select_related_descend(field, restricted, requested):
"""
Returns True if this field should be used to descend deeper for
select_related() purposes. Used by both the query construction code
(sql.query.fill_related_selections()) and the model instance creation code
(query.get_cached_row()).
"""
if not field.rel:
return False
if field.rel.parent_link:
return False
if restricted and field.name not in requested:
return False
if not restricted and field.null:
return False
return True