Opened 16 years ago
Closed 16 years ago
#8144 closed (wontfix)
values_list doesn't give the full object when requested
Reported by: | Kenneth Arnold | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Keywords: | values_list | |
Cc: | kenneth.arnold@… | Triage Stage: | Design decision needed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
values_list
is very useful to us, but one thing that keeps it from being more useful is that it will not return full objects when we ask for them.
Current behavior:
Model.objects.values_list('other') # yields ids
Desired behavior:
Model.objects.values_list('other_id') # yields ids Model.objects.values_list('other') # yields objects
This of course requires getting extra things from the database, akin to select_related
. We prefer values_list
because it is more explicit and doesn't require pulling in all the fields of the first model (Model
, above) where we don't ask for them.
Change History (2)
comment:1 by , 16 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
comment:2 by , 16 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
This would be a backwards-incompatible change and not necessarily desirable behaviour for everybody. Also,
values_list()
is just another presentation for ofvalues()
, so should always mirror that (and changingvalues()
behaviour would affect a lot of people). The solution here is to write your ownQuerySet
subclass that does the conversion you're after.One day, maybe, if there's a really good API, we might support this in core, but, really,
values()
andvalues_list()
return raw values intentionally. If you want Python objects, just use a normal QuerySet.