If I have some models like so:
from django.db import models
class X(models.Model):
y = models.ForeignKey(Y)
... other fields ...
class Y(models.Model):
... some fields ...
... and I do a query like so:
X.objects.all().values('y')
... I get back a list of dictionaries that contain Y ID integers.
If I do a query like so:
X.objects.all().values('y_id')
...I get back a similar result, except for the keys in the dictionaries.
My proposal is to differentiate between those two calls and in the former
case, instead of returning the same results as the latter case, return Y
model objects.
Not only would this produce results that are more indicative of what the
query is asking for, but it would extend the ORM in at least one area:
http://stackoverflow.com/questions/30113766/aggregrate-query-with-related-models-not-just-related-id-values
Those kinds of aggregrate queries would be possible.
As far as backwards compatibility is concerned, the old behaviour could
occur with no key word argument to the values() call, but if a keyword
argument like so:
X.objects.all().values('y', select_related=True)
...is specified, then my proposed behaviour could be executed.
What do you think?
--
You received this message because you are subscribed to the Google Groups
"Django developers (Contributions to Django itself)" 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].
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-developers/4adaa5a3-f6d3-4189-8bb5-83eb5c4f2648%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.