Pull Request at https://github.com/django/django/pull/5004
--
Ticket URL: <https://code.djangoproject.com/ticket/25132>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
I think this could live on a custom queryset just fine (or even as free
method), I cannot remember when I'd ever would have needed something like
this. I know we have a few of "syntax sugar" methods like first and last,
but those are used really often in code and having that as nice oneliners
makes sense.
--
Ticket URL: <https://code.djangoproject.com/ticket/25132#comment:1>
* easy: 1 => 0
Comment:
I'm not particularly enthusiastic either, but it's better to first propose
new APIs like this on the DevelopersMailingList so that the discussion
involves a wider audience. I did notice that this patterns appears about
25 times in the test suite (`grep -rI "only(" * | grep "get(" | wc -l`),
sometimes `only()` involves multiple fields though.
--
Ticket URL: <https://code.djangoproject.com/ticket/25132#comment:2>
Comment (by charettes):
FWIW this is already achievable with `values_list('pk',
flat=True).get(name='foo')`.
While we can argue the latter is a bit verbose I don't think the use case
is common enough to warrant an addition to the QuerySet API.
--
Ticket URL: <https://code.djangoproject.com/ticket/25132#comment:3>
Comment (by thedrow):
It is worth a documentation change at the very least.
--
Ticket URL: <https://code.djangoproject.com/ticket/25132#comment:4>
Comment (by thedrow):
Also I added a bit of coverage for get(). Should I open a separate PR with
those tests alone?
--
Ticket URL: <https://code.djangoproject.com/ticket/25132#comment:5>
Comment (by timgraham):
I would think `get()` is pretty well tested by now. `tests/basic` seems to
cover the simple stuff and the [http://djangoci.com/job/django-
coverage/HTML_Coverage_Report/ coverage report] doesn't report any
untested lines. Of course, if you think you have something new to offer,
we'll take a look.
--
Ticket URL: <https://code.djangoproject.com/ticket/25132#comment:6>
Comment (by thedrow):
I missed those. The tests are not very well organized for those who are
unfamiliar with their structure. I guess I should try to contribute more
:)
I'm not worry about the time I spent about this method as I learned
something new about Django and because something might come out of it
anyway,
I think we can close this issue and file a new one about documenting what
charettes suggested because it's not something that is either widely known
or intuitive. I expected to get a list/tuple even with flat=True.
--
Ticket URL: <https://code.djangoproject.com/ticket/25132#comment:7>
* has_patch: 1 => 0
* component: Database layer (models, ORM) => Documentation
* easy: 0 => 1
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/25132#comment:8>
* status: new => closed
* component: Documentation => Database layer (models, ORM)
* easy: 1 => 0
* has_patch: 0 => 1
* resolution: => wontfix
* stage: Accepted => Unreviewed
--
Ticket URL: <https://code.djangoproject.com/ticket/25132#comment:9>
* status: closed => new
* resolution: wontfix =>
--
Ticket URL: <https://code.djangoproject.com/ticket/25132#comment:10>
Comment (by thedrow):
Sorry about that. Race condition :P
--
Ticket URL: <https://code.djangoproject.com/ticket/25132#comment:11>
* component: Database layer (models, ORM) => Documentation
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/25132#comment:12>
* has_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/25132#comment:13>
* easy: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/25132#comment:14>
Comment (by thedrow):
Where do you guys think that this fits? In the queryset guide?
--
Ticket URL: <https://code.djangoproject.com/ticket/25132#comment:15>
Comment (by timgraham):
Probably either in `ref/models/querysets.txt` under `values_list` or
somewhere in `topics/db/queries.txt`.
--
Ticket URL: <https://code.djangoproject.com/ticket/25132#comment:16>
* status: new => assigned
* owner: nobody => donaldharvey
--
Ticket URL: <https://code.djangoproject.com/ticket/25132#comment:17>
* owner: donaldharvey => alexmorozov
Comment:
PR is on it`s way.
--
Ticket URL: <https://code.djangoproject.com/ticket/25132#comment:18>
* has_patch: 0 => 1
Comment:
https://github.com/django/django/pull/5534
--
Ticket URL: <https://code.djangoproject.com/ticket/25132#comment:19>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"4373eac99828d99718a7b245d160e7e64fce2e95" 4373eac]:
{{{
#!CommitTicketReference repository=""
revision="4373eac99828d99718a7b245d160e7e64fce2e95"
Fixed #25132 -- Documented how to retrieve a single value using
values_list() and get().
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25132#comment:20>
Comment (by Tim Graham <timograham@…>):
In [changeset:"ecb3e314cb0ce4b7fe65e208ea76557443ae6e06" ecb3e314]:
{{{
#!CommitTicketReference repository=""
revision="ecb3e314cb0ce4b7fe65e208ea76557443ae6e06"
[1.9.x] Fixed #25132 -- Documented how to retrieve a single value using
values_list() and get().
Backport of 4373eac99828d99718a7b245d160e7e64fce2e95 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25132#comment:21>
Comment (by Tim Graham <timograham@…>):
In [changeset:"676636ac8f2fa612d68045dd747df7bf2bf8da99" 676636ac]:
{{{
#!CommitTicketReference repository=""
revision="676636ac8f2fa612d68045dd747df7bf2bf8da99"
[1.8.x] Fixed #25132 -- Documented how to retrieve a single value using
values_list() and get().
Backport of 4373eac99828d99718a7b245d160e7e64fce2e95 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25132#comment:22>