summaryrefslogtreecommitdiff
path: root/django/db/models/query_utils.py
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-06-29 09:40:17 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-06-29 09:40:17 +0000
commit5326cd293ef39408c325d592afdb87cb432007bd (patch)
tree4b0ee96fa9bd6d20b3b1d23cd853b9281d2255fe /django/db/models/query_utils.py
parenta8fa3fd81fee316144986328f3df1e811015f1d9 (diff)
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
Diffstat (limited to 'django/db/models/query_utils.py')
-rw-r--r--django/db/models/query_utils.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/django/db/models/query_utils.py b/django/db/models/query_utils.py
index 0ce7900c74..8dbb1ec667 100644
--- a/django/db/models/query_utils.py
+++ b/django/db/models/query_utils.py
@@ -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
+