Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Fixes #2271 -- Added code to imply !__exact on any query argument tha…

…t doesn't finish with a known query term.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit cd7b54aab0c087ba6efd4a86ae0ecb6ed55d7e4b 1 parent 4a324ba
@freakboy3742 freakboy3742 authored
17 django/db/models/
@@ -10,8 +10,20 @@
if not hasattr(__builtins__, 'set'):
from sets import Set as set
+# The string constant used to separate query parts
+# The list of valid query types
+ 'exact', 'iexact',
+ 'contains', 'icontains',
+ 'gt', 'gte', 'lt', 'lte',
+ 'in',
+ 'startswith', 'istartswith', 'endswith', 'iendswith',
+ 'range', 'year', 'month', 'day',
+ 'isnull'
# Size of each "chunk" for get_iterator calls.
# Larger values are slightly faster at the expense of more storage space.
@@ -710,12 +722,13 @@ def parse_lookup(kwarg_items, opts):
# if we find "pk", make the clause "exact', and insert
# a dummy name of None, which we will replace when
# we know which table column to grab as the primary key.
- # 2) If there is only one part, assume it to be an __exact
+ # 2) If there is only one part, or the last part is not a query
+ # term, assume that the query is an __exact
clause = path.pop()
if clause == 'pk':
clause = 'exact'
- elif len(path) == 0:
+ elif len(path) == 0 or clause not in QUERY_TERMS:
clause = 'exact'
8 tests/modeltests/many_to_one/
@@ -136,6 +136,10 @@ class Meta:
>>> Article.objects.filter(reporter__first_name__exact='John')
[<Article: John's second story>, <Article: This is a test>]
+# Check that implied __exact also works
+>>> Article.objects.filter(reporter__first_name='John')
+[<Article: John's second story>, <Article: This is a test>]
# Query twice over the related field.
>>> Article.objects.filter(reporter__first_name__exact='John', reporter__last_name__exact='Smith')
[<Article: John's second story>, <Article: This is a test>]
@@ -237,6 +241,10 @@ class Meta:
>>> Reporter.objects.filter(article__reporter__exact=r).distinct()
[<Reporter: John Smith>]
+# Check that implied __exact also works
+>>> Reporter.objects.filter(article__reporter=r).distinct()
+[<Reporter: John Smith>]
# If you delete a reporter, his articles will be deleted.
>>> Article.objects.all()
[<Article: John's second story>, <Article: Paul's story>, <Article: This is a test>, <Article: This is a test>, <Article: This is a test>]

0 comments on commit cd7b54a

Please sign in to comment.
Something went wrong with that request. Please try again.