Django

Code

Changeset 3248

Show
Ignore:
Timestamp:
06/30/06 22:14:33 (2 years ago)
Author:
russellm
Message:

Fixes #2271 -- Added code to imply __exact on any query argument that doesn't finish with a known query term.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/models/query.py

    r3246 r3248  
    1111    from sets import Set as set 
    1212 
     13# The string constant used to separate query parts 
    1314LOOKUP_SEPARATOR = '__' 
     15 
     16# The list of valid query types  
     17QUERY_TERMS=( 
     18    'exact', 'iexact', 
     19    'contains', 'icontains', 
     20    'gt', 'gte', 'lt', 'lte', 
     21    'in', 
     22    'startswith', 'istartswith', 'endswith', 'iendswith', 
     23    'range', 'year', 'month', 'day', 
     24    'isnull' 
     25) 
    1426 
    1527# Size of each "chunk" for get_iterator calls. 
     
    711723            #     a dummy name of None, which we will replace when 
    712724            #     we know which table column to grab as the primary key. 
    713             # 2)  If there is only one part, assume it to be an __exact 
     725            # 2)  If there is only one part, or the last part is not a query 
     726            #     term, assume that the query is an __exact             
    714727            clause = path.pop() 
    715728            if clause == 'pk': 
    716729                clause = 'exact' 
    717730                path.append(None) 
    718             elif len(path) == 0
     731            elif len(path) == 0 or clause not in QUERY_TERMS
    719732                path.append(clause) 
    720733                clause = 'exact' 
  • django/trunk/tests/modeltests/many_to_one/models.py

    r3246 r3248  
    137137[<Article: John's second story>, <Article: This is a test>] 
    138138 
     139# Check that implied __exact also works 
     140>>> Article.objects.filter(reporter__first_name='John') 
     141[<Article: John's second story>, <Article: This is a test>] 
     142 
    139143# Query twice over the related field. 
    140144>>> Article.objects.filter(reporter__first_name__exact='John', reporter__last_name__exact='Smith') 
     
    236240[<Reporter: John Smith>] 
    237241>>> Reporter.objects.filter(article__reporter__exact=r).distinct() 
     242[<Reporter: John Smith>] 
     243 
     244# Check that implied __exact also works 
     245>>> Reporter.objects.filter(article__reporter=r).distinct() 
    238246[<Reporter: John Smith>] 
    239247