summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-04-24 11:11:30 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-04-24 11:11:30 +0000
commit9d6f0f9e1085d963d96168efaf07315613cb8cc0 (patch)
tree1cf5fe92ac50f570d575c3f43e9ac0b0eb39c53c
parent27b0a4c4e7cb491b24c802f00e06ae0c6b3cc57d (diff)
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). git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7451 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/db/models/manager.py4
-rw-r--r--django/db/models/query.py6
-rw-r--r--docs/db-api.txt12
-rw-r--r--tests/modeltests/lookup/models.py20
4 files changed, 21 insertions, 21 deletions
diff --git a/django/db/models/manager.py b/django/db/models/manager.py
index d58a1c75d0..3a9da34a49 100644
--- a/django/db/models/manager.py
+++ b/django/db/models/manager.py
@@ -114,8 +114,8 @@ class Manager(object):
def values(self, *args, **kwargs):
return self.get_query_set().values(*args, **kwargs)
- def valueslist(self, *args, **kwargs):
- return self.get_query_set().valueslist(*args, **kwargs)
+ def values_list(self, *args, **kwargs):
+ return self.get_query_set().values_list(*args, **kwargs)
def update(self, *args, **kwargs):
return self.get_query_set().update(*args, **kwargs)
diff --git a/django/db/models/query.py b/django/db/models/query.py
index 5cffbe814c..5a501bb09d 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -307,13 +307,13 @@ class QuerySet(object):
def values(self, *fields):
return self._clone(klass=ValuesQuerySet, setup=True, _fields=fields)
- def valueslist(self, *fields, **kwargs):
+ def values_list(self, *fields, **kwargs):
flat = kwargs.pop('flat', False)
if kwargs:
- raise TypeError('Unexpected keyword arguments to valueslist: %s'
+ raise TypeError('Unexpected keyword arguments to values_list: %s'
% (kwargs.keys(),))
if flat and len(fields) > 1:
- raise TypeError("'flat' is not valid when valueslist is called with more than one field.")
+ raise TypeError("'flat' is not valid when values_list is called with more than one field.")
return self._clone(klass=ValuesListQuerySet, setup=True, flat=flat,
_fields=fields)
diff --git a/docs/db-api.txt b/docs/db-api.txt
index 9dd64d0508..bda7cb7571 100644
--- a/docs/db-api.txt
+++ b/docs/db-api.txt
@@ -648,32 +648,32 @@ followed (optionally) by any output-affecting methods (such as ``values()``),
but it doesn't really matter. This is your chance to really flaunt your
individualism.
-``valueslist(*fields)``
+``values_list(*fields)``
~~~~~~~~~~~~~~~~~~~~~~~
**New in Django development version**
This is similar to ``values()`` except that instead of returning a list of
dictionaries, it returns a list of tuples. Each tuple contains the value from
-the respective field passed into the ``valueslist()`` call -- so the first
+the respective field passed into the ``values_list()`` call -- so the first
item is the first field, etc. For example::
- >>> Entry.objects.valueslist('id', 'headling')
+ >>> Entry.objects.values_list('id', 'headling')
[(1, u'First entry'), ...]
If you only pass in a single field, you can also pass in the ``flat``
parameter. If ``True``, this will mean the returned results are single values,
rather than one-tuples. An example should make the difference clearer::
- >>> Entry.objects.valueslist('id').order_by('id')
+ >>> Entry.objects.values_list('id').order_by('id')
[(1,), (2,), (3,), ...]
- >>> Entry.objects.valueslist('id', flat=True).order_by('id')
+ >>> Entry.objects.values_list('id', flat=True).order_by('id')
[1, 2, 3, ...]
It is an error to pass in ``flat`` when there is more than one field.
-If you don't pass any values to ``valueslist()``, it will return all the
+If you don't pass any values to ``values_list()``, it will return all the
fields in the model, in the order they were declared.
``dates(field, kind, order='ASC')``
diff --git a/tests/modeltests/lookup/models.py b/tests/modeltests/lookup/models.py
index d134fb5265..7a53e93aec 100644
--- a/tests/modeltests/lookup/models.py
+++ b/tests/modeltests/lookup/models.py
@@ -168,29 +168,29 @@ FieldError: Cannot resolve keyword 'id_plus_two' into field. Choices are: headli
>>> list(Article.objects.filter(id=5).values()) == [{'id': 5, 'headline': 'Article 5', 'pub_date': datetime(2005, 8, 1, 9, 0)}]
True
-# valueslist() is similar to values(), except that the results are returned as
+# values_list() is similar to values(), except that the results are returned as
# a list of tuples, rather than a list of dictionaries. Within each tuple, the
-# order of the elemnts is the same as the order of fields in the valueslist()
+# order of the elemnts is the same as the order of fields in the values_list()
# call.
->>> Article.objects.valueslist('headline')
+>>> Article.objects.values_list('headline')
[(u'Article 5',), (u'Article 6',), (u'Article 4',), (u'Article 2',), (u'Article 3',), (u'Article 7',), (u'Article 1',)]
->>> Article.objects.valueslist('id').order_by('id')
+>>> Article.objects.values_list('id').order_by('id')
[(1,), (2,), (3,), (4,), (5,), (6,), (7,)]
->>> Article.objects.valueslist('id', flat=True).order_by('id')
+>>> Article.objects.values_list('id', flat=True).order_by('id')
[1, 2, 3, 4, 5, 6, 7]
->>> Article.objects.extra(select={'id_plus_one': 'id+1'}).order_by('id').valueslist('id')
+>>> Article.objects.extra(select={'id_plus_one': 'id+1'}).order_by('id').values_list('id')
[(1,), (2,), (3,), (4,), (5,), (6,), (7,)]
->>> Article.objects.extra(select={'id_plus_one': 'id+1'}).order_by('id').valueslist('id_plus_one', 'id')
+>>> Article.objects.extra(select={'id_plus_one': 'id+1'}).order_by('id').values_list('id_plus_one', 'id')
[(2, 1), (3, 2), (4, 3), (5, 4), (6, 5), (7, 6), (8, 7)]
->>> Article.objects.extra(select={'id_plus_one': 'id+1'}).order_by('id').valueslist('id', 'id_plus_one')
+>>> Article.objects.extra(select={'id_plus_one': 'id+1'}).order_by('id').values_list('id', 'id_plus_one')
[(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 8)]
->>> Article.objects.valueslist('id', 'headline', flat=True)
+>>> Article.objects.values_list('id', 'headline', flat=True)
Traceback (most recent call last):
...
-TypeError: 'flat' is not valid when valueslist is called with more than one field.
+TypeError: 'flat' is not valid when values_list is called with more than one field.
# Every DateField and DateTimeField creates get_next_by_FOO() and
# get_previous_by_FOO() methods.