I could also use a couple of enhancement to this:

1) Allow renaming of keys, instead of using the database column names.  
2) Allow callbacks functions (or lambdas) to convert output values to another 
format if needed.

With this, I could send the queries results right to JSON outputs.

-bobby

> On Nov 25, 2015, at 9:05 AM, Moenad <[email protected]> wrote:
> 
> Currently, after calling values() and the query executes, the output is a 
> single level dictionary, including foreign keys. I propose adding an extra 
> parameter for values, or at least values_list, where if it's set to true, a 
> nested dictionary will be returned when there's a foreign key.
> 
> Example:
> 
> Person model with the following fields: first_name, last_name and hometown 
> (foreign key)
> Hometown model with the following fields: name
> 
> A single record from Person.objects.values() will looks like this
> 
> {"id": 1
>  "first_name": "first name",
>  "last_name": "last name",
>  "hometown__id": 1,
>  "hometown__name": "town name",
> }
> 
> 
> I propose adding a nested optional parameter to values, where a single record 
> from Person.objects.values(nested=True) will look like
> 
> {"id": 1
>  "first_name": "first name",
>  "last_name": "last name",
>  "hometown": {
>       "id": 1,
>       "name": "town name"
>   }
> }
> 
> 
> This feature is needed given that most APIs these days are nested, while it's 
> simple to implement, I think it's much better to have it a built-in django 
> feature.
> 
> 
> -- 
> 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] 
> <mailto:[email protected]>.
> To post to this group, send email to [email protected] 
> <mailto:[email protected]>.
> Visit this group at http://groups.google.com/group/django-developers 
> <http://groups.google.com/group/django-developers>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-developers/8e5cbc9a-0317-40d3-8038-5b4300738b90%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-developers/8e5cbc9a-0317-40d3-8038-5b4300738b90%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
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/2719FB24-E00F-4C85-BD9A-FF1FB2EB3799%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to