Django

Code

Show
Ignore:
Timestamp:
04/26/08 21:50:16 (7 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/lookup/models.py

    r7322 r7477  
    163163Traceback (most recent call last): 
    164164    ... 
    165 FieldDoesNotExist: Article has no field named 'id_plus_two' 
     165FieldError: Cannot resolve keyword 'id_plus_two' into field. Choices are: headline, id, id_plus_one, pub_date 
    166166 
    167167# If you don't specify field names to values(), all are returned. 
    168168>>> list(Article.objects.filter(id=5).values()) == [{'id': 5, 'headline': 'Article 5', 'pub_date': datetime(2005, 8, 1, 9, 0)}] 
    169169True 
     170 
     171# values_list() is similar to values(), except that the results are returned as 
     172# a list of tuples, rather than a list of dictionaries. Within each tuple, the 
     173# order of the elemnts is the same as the order of fields in the values_list() 
     174# call. 
     175>>> Article.objects.values_list('headline') 
     176[(u'Article 5',), (u'Article 6',), (u'Article 4',), (u'Article 2',), (u'Article 3',), (u'Article 7',), (u'Article 1',)] 
     177 
     178>>> Article.objects.values_list('id').order_by('id') 
     179[(1,), (2,), (3,), (4,), (5,), (6,), (7,)] 
     180>>> Article.objects.values_list('id', flat=True).order_by('id') 
     181[1, 2, 3, 4, 5, 6, 7] 
     182 
     183>>> Article.objects.extra(select={'id_plus_one': 'id+1'}).order_by('id').values_list('id') 
     184[(1,), (2,), (3,), (4,), (5,), (6,), (7,)] 
     185>>> Article.objects.extra(select={'id_plus_one': 'id+1'}).order_by('id').values_list('id_plus_one', 'id') 
     186[(2, 1), (3, 2), (4, 3), (5, 4), (6, 5), (7, 6), (8, 7)] 
     187>>> Article.objects.extra(select={'id_plus_one': 'id+1'}).order_by('id').values_list('id', 'id_plus_one') 
     188[(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 8)] 
     189 
     190>>> Article.objects.values_list('id', 'headline', flat=True) 
     191Traceback (most recent call last): 
     192... 
     193TypeError: 'flat' is not valid when values_list is called with more than one field. 
    170194 
    171195# Every DateField and DateTimeField creates get_next_by_FOO() and 
     
    241265>>> Article.objects.none().filter(headline__startswith='Article') 
    242266[] 
     267>>> Article.objects.filter(headline__startswith='Article').none() 
     268[] 
    243269>>> Article.objects.none().count() 
    2442700 
     
    257283Traceback (most recent call last): 
    258284    ... 
    259 TypeError: Cannot resolve keyword 'pub_date_year' into field. Choices are: id, headline, pub_date 
     285FieldError: Cannot resolve keyword 'pub_date_year' into field. Choices are: headline, id, pub_date 
    260286 
    261287>>> Article.objects.filter(headline__starts='Article') 
    262288Traceback (most recent call last): 
    263289    ... 
    264 TypeError: Cannot resolve keyword 'headline__starts' into field. Choices are: id, headline, pub_date 
     290FieldError: Join on field 'headline' not permitted. 
    265291 
    266292# Create some articles with a bit more interesting headlines for testing field lookups: