I spent a while struggling to understand why I couldn't use the Python
x.count(y) function on the output of such a query before realizing that I
wasn't working with a Python list:
{{{
> rlist = Rpt.objects.values_list('status', flat=True)
> type(rlist)
django.db.models.query.ValuesListQuerySet
> rlist.count(1)
TypeError: count() takes exactly 1 argument (2 given)
> rlist2 = list(Rpt.objects.values_list('status', flat=True))
> rlist2.count(1)
6
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/20408>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_docs: => 0
Comment:
Sounds like a reasonable addition.
--
Ticket URL: <https://code.djangoproject.com/ticket/20408#comment:1>
* status: new => assigned
* owner: nobody => EvilDMP
Comment:
I have tentatively reserved this ticket for first-time committers who take
part in the [https://dont-be-afraid-to-commit.readthedocs.org/ Don't be
afraid to commit workshop] at the [http://2013.djangocon.eu/ DjangoCon
Europe 2013] sprints on 18th and 19th May.
If you want to tackle this ticket before then, please '''don't''' let the
fact that it's assigned to me stop you. Feel free to re-assign it to
yourself and do whatever you like to it.
--
Ticket URL: <https://code.djangoproject.com/ticket/20408#comment:2>
* owner: EvilDMP => alextreme
--
Ticket URL: <https://code.djangoproject.com/ticket/20408#comment:3>
* has_patch: 0 => 1
Comment:
Added a patch to clarify the values_list() documentation.
--
Ticket URL: <https://code.djangoproject.com/ticket/20408#comment:4>
Comment (by bmispelon):
How about something like that:
Note that this method returns a VLQS which is an object that behaves like
a list. Most of the time this is enough, but if you require an actual
python
list object, you can simply call list() on it (which will evaluate the
queryset).
--
Ticket URL: <https://code.djangoproject.com/ticket/20408#comment:5>
Comment (by alextreme):
Thanks, the ticket has been updated.
--
Ticket URL: <https://code.djangoproject.com/ticket/20408#comment:6>
* stage: Accepted => Ready for checkin
Comment:
Looks good. Thanks for the patch!
--
Ticket URL: <https://code.djangoproject.com/ticket/20408#comment:7>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"7b85ef9dfb83bd2f2cde46b9836b9fd12a033b26"]:
{{{
#!CommitTicketReference repository=""
revision="7b85ef9dfb83bd2f2cde46b9836b9fd12a033b26"
Fixed #20408 -- Clarified that values_list() doesn't return a list.
Thanks marktranchant, bmispelon, and alextreme.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/20408#comment:8>