Django

Code

Show
Ignore:
Timestamp:
04/26/08 21:50:16 (9 months ago)
Author:
mtredinnick
Message:

Merged the queryset-refactor branch into trunk.

This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.

Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/tests/modeltests/many_to_one/models.py

    r5876 r7477  
    146146 
    147147# The underlying query only makes one join when a related table is referenced twice. 
    148 >>> query = Article.objects.filter(reporter__first_name__exact='John', reporter__last_name__exact='Smith') 
    149 >>> null, sql, null = query._get_sql_clause() 
     148>>> queryset = Article.objects.filter(reporter__first_name__exact='John', reporter__last_name__exact='Smith') 
     149>>> sql = queryset.query.as_sql()[0] 
    150150>>> sql.count('INNER JOIN') 
    1511511 
    152152 
    153153# The automatically joined table has a predictable name. 
    154 >>> Article.objects.filter(reporter__first_name__exact='John').extra(where=["many_to_one_article__reporter.last_name='Smith'"]) 
     154>>> Article.objects.filter(reporter__first_name__exact='John').extra(where=["many_to_one_reporter.last_name='Smith'"]) 
    155155[<Article: John's second story>, <Article: This is a test>] 
    156156 
    157157# And should work fine with the unicode that comes out of 
    158158# newforms.Form.cleaned_data 
    159 >>> Article.objects.filter(reporter__first_name__exact='John').extra(where=["many_to_one_article__reporter.last_name='%s'" % u'Smith']) 
     159>>> Article.objects.filter(reporter__first_name__exact='John').extra(where=["many_to_one_reporter.last_name='%s'" % u'Smith']) 
    160160[<Article: John's second story>, <Article: This is a test>] 
    161161 
     
    180180Traceback (most recent call last): 
    181181    ... 
    182 TypeError: Cannot resolve keyword 'reporter_id' into field. Choices are: id, headline, pub_date, reporter 
     182FieldError: Cannot resolve keyword 'reporter_id' into field. Choices are: headline, id, pub_date, reporter 
    183183 
    184184# You need to specify a comparison clause 
     
    186186Traceback (most recent call last): 
    187187    ... 
    188 TypeError: Cannot resolve keyword 'reporter_id' into field. Choices are: id, headline, pub_date, reporter 
     188FieldError: Cannot resolve keyword 'reporter_id' into field. Choices are: headline, id, pub_date, reporter 
    189189 
    190190# You can also instantiate an Article by passing 
     
    250250>>> Reporter.objects.filter(article__reporter=r).distinct() 
    251251[<Reporter: John Smith>] 
     252 
     253# It's possible to use values() calls across many-to-one relations. (Note, too, that we clear the ordering here so as not to drag the 'headline' field into the columns being used to determine uniqueness.) 
     254>>> d = {'reporter__first_name': u'John', 'reporter__last_name': u'Smith'} 
     255>>> list(Article.objects.filter(reporter=r).distinct().order_by().values('reporter__first_name', 'reporter__last_name')) == [d] 
     256True 
    252257 
    253258# If you delete a reporter, his articles will be deleted.