Django

Code

Changeset 7451

Show
Ignore:
Timestamp:
04/24/08 06:11:30 (2 months ago)
Author:
mtredinnick
Message:

queryset-refactor: Renamed the Queryset method valueslist() to values_list.

Suggested by Michael Trier. It's more consistent with order_by, select_related,
etc. This is backwards incompatible for people previously using this method on
the branch (the method doesn't exist on trunk, so it's very minor).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/queryset-refactor/django/db/models/manager.py

    r7437 r7451  
    115115        return self.get_query_set().values(*args, **kwargs) 
    116116 
    117     def valueslist(self, *args, **kwargs): 
    118         return self.get_query_set().valueslist(*args, **kwargs) 
     117    def values_list(self, *args, **kwargs): 
     118        return self.get_query_set().values_list(*args, **kwargs) 
    119119 
    120120    def update(self, *args, **kwargs): 
  • django/branches/queryset-refactor/django/db/models/query.py

    r7446 r7451  
    308308        return self._clone(klass=ValuesQuerySet, setup=True, _fields=fields) 
    309309 
    310     def valueslist(self, *fields, **kwargs): 
     310    def values_list(self, *fields, **kwargs): 
    311311        flat = kwargs.pop('flat', False) 
    312312        if kwargs: 
    313             raise TypeError('Unexpected keyword arguments to valueslist: %s' 
     313            raise TypeError('Unexpected keyword arguments to values_list: %s' 
    314314                    % (kwargs.keys(),)) 
    315315        if flat and len(fields) > 1: 
    316             raise TypeError("'flat' is not valid when valueslist is called with more than one field.") 
     316            raise TypeError("'flat' is not valid when values_list is called with more than one field.") 
    317317        return self._clone(klass=ValuesListQuerySet, setup=True, flat=flat, 
    318318                _fields=fields) 
  • django/branches/queryset-refactor/docs/db-api.txt

    r7448 r7451  
    649649individualism. 
    650650 
    651 ``valueslist(*fields)`` 
     651``values_list(*fields)`` 
    652652~~~~~~~~~~~~~~~~~~~~~~~ 
    653653 
     
    656656This is similar to ``values()`` except that instead of returning a list of 
    657657dictionaries, it returns a list of tuples. Each tuple contains the value from 
    658 the respective field passed into the ``valueslist()`` call -- so the first 
     658the respective field passed into the ``values_list()`` call -- so the first 
    659659item is the first field, etc. For example:: 
    660660 
    661     >>> Entry.objects.valueslist('id', 'headling') 
     661    >>> Entry.objects.values_list('id', 'headling') 
    662662    [(1, u'First entry'), ...] 
    663663 
     
    666666rather than one-tuples. An example should make the difference clearer:: 
    667667 
    668     >>> Entry.objects.valueslist('id').order_by('id') 
     668    >>> Entry.objects.values_list('id').order_by('id') 
    669669    [(1,), (2,), (3,), ...] 
    670670 
    671     >>> Entry.objects.valueslist('id', flat=True).order_by('id') 
     671    >>> Entry.objects.values_list('id', flat=True).order_by('id') 
    672672    [1, 2, 3, ...] 
    673673 
    674674It is an error to pass in ``flat`` when there is more than one field. 
    675675 
    676 If you don't pass any values to ``valueslist()``, it will return all the 
     676If you don't pass any values to ``values_list()``, it will return all the 
    677677fields in the model, in the order they were declared. 
    678678 
  • django/branches/queryset-refactor/tests/modeltests/lookup/models.py

    r7446 r7451  
    169169True 
    170170 
    171 # valueslist() is similar to values(), except that the results are returned as 
     171# values_list() is similar to values(), except that the results are returned as 
    172172# 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 valueslist() 
     173# order of the elemnts is the same as the order of fields in the values_list() 
    174174# call. 
    175 >>> Article.objects.valueslist('headline') 
     175>>> Article.objects.values_list('headline') 
    176176[(u'Article 5',), (u'Article 6',), (u'Article 4',), (u'Article 2',), (u'Article 3',), (u'Article 7',), (u'Article 1',)] 
    177177 
    178 >>> Article.objects.valueslist('id').order_by('id') 
     178>>> Article.objects.values_list('id').order_by('id') 
    179179[(1,), (2,), (3,), (4,), (5,), (6,), (7,)] 
    180 >>> Article.objects.valueslist('id', flat=True).order_by('id') 
     180>>> Article.objects.values_list('id', flat=True).order_by('id') 
    181181[1, 2, 3, 4, 5, 6, 7] 
    182182 
    183 >>> Article.objects.extra(select={'id_plus_one': 'id+1'}).order_by('id').valueslist('id') 
     183>>> Article.objects.extra(select={'id_plus_one': 'id+1'}).order_by('id').values_list('id') 
    184184[(1,), (2,), (3,), (4,), (5,), (6,), (7,)] 
    185 >>> Article.objects.extra(select={'id_plus_one': 'id+1'}).order_by('id').valueslist('id_plus_one', 'id') 
     185>>> Article.objects.extra(select={'id_plus_one': 'id+1'}).order_by('id').values_list('id_plus_one', 'id') 
    186186[(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').valueslist('id', 'id_plus_one') 
     187>>> Article.objects.extra(select={'id_plus_one': 'id+1'}).order_by('id').values_list('id', 'id_plus_one') 
    188188[(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 8)] 
    189189 
    190 >>> Article.objects.valueslist('id', 'headline', flat=True) 
     190>>> Article.objects.values_list('id', 'headline', flat=True) 
    191191Traceback (most recent call last): 
    192192... 
    193 TypeError: 'flat' is not valid when valueslist is called with more than one field. 
     193TypeError: 'flat' is not valid when values_list is called with more than one field. 
    194194 
    195195# Every DateField and DateTimeField creates get_next_by_FOO() and