I would really like two things for values to support.
1. Aliases .values(alias='field');
2. Expressions .values(alias=F('field'))
I think these two features are absolute must haves, and the syntaxes above
are already standard in other parts of the ORM.
If someone can come up with a way to support nested relations while
supporting the above syntax, then I'd be OK with that. But at the moment,
I'm firmly in the "this is the responsibility of a serialiser" camp. I'm
not convinced Django needs to support nested objects at all. Is this
something you could implement with your own queryset method on a manager?
Is this maybe something we could look at creating a new queryset method
called .values_dict() ?
If it weren't for backwards compatibility, I'd suggest that referencing the
related object would automatically nest that object. That would
differentiate between the id and the field values('related_id', 'related')
-> '{"related_id": 1, "related": {"id": 1, ..}}'.
If there's (rough) consensus on having nested objects, then we could allow
something like: .values(..., ..., nested=('related',
'related__otherrelated')). If the value of nested is an iterable then
assume we're nesting, otherwise nested is an alias for the field. I don't
particularly like overloaded kwargs, but we're just guarding against
someone wanting to alias as "nested" which we could call out in docs anyway.
The more I think about this the more I think nesting and aliases within a
nest should probably be done in a different queryset method. Or just
handled by a serialiser. If you want more requests per second, then add
some more backends.
--
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/35310a81-737b-43e1-b034-94d68f9ffd0f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.