#27535: RFE: Exclude pk from queries
-------------------------------------+-------------------------------------
Reporter: Alexander Todorov | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Shai Berger):
Hi Alexander, thanks for this suggestion.
The value of the PK is the link between the object in memory and the
record in the database. An object with deferred fields must have it, or
else any access to the deferred fields would be an error.
It seems like you can get what you want with some variation on the
following (caveat: untested)
{{{
def values_as_objects(values_qset, model, *fields):
for values in values_qset:
obj = model(**{field: values[field] for field in fields})
for k,v in values.items():
if k not in fields:
setattr(obj, k, v)
yield obj
# or if you want to make it a little more complicated to write and
easier to use,
# you can get the model from the qset and the fields from the model)
objs =
values_as_objects(Book.objects.values('genre').annotate(whatever=...),
Book, 'genre')
}}}
while adding any of the requested features to Django querysets in general
would, IMO, make the API much less clear and consistent.
(my original opinion was that this should be wontfix'ed, but in view of
Tim's comment I am waiting for more input)
--
Ticket URL: <https://code.djangoproject.com/ticket/27535#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/066.d5598e70f79a88d2e1207341c82307b1%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.