Need example to implement sql (dictionary) translations

35 views
Skip to first unread message

robert brook

unread,
Sep 29, 2014, 1:11:51 PM9/29/14
to django...@googlegroups.com
From the django project web site, I am trying to implement the following code and have it spit out the dictionary form of the sql.

Does anyone have an example of how this is done.

The code below is from the project web page



When I execute the 2 lines below I retrieve the following
<RawQuerySet: 'SELECT first_name AS first, last_name AS last FROM person'>

Does anyone have an example so that  I can get this into a dictionary format so that I can send it back to the web page for consumption?

>>> name_map = {'first': 'first_name', 'last': 'last_name', 'bd': 'birth_date', 'pk': 'id'}
>>> Person.objects.raw('SELECT * FROM some_other_table', translations=name_map)

Collin Anderson

unread,
Sep 29, 2014, 4:14:30 PM9/29/14
to django...@googlegroups.com
does list(your_raw_query) return what you want?

robert brook

unread,
Sep 30, 2014, 7:35:56 AM9/30/14
to django...@googlegroups.com
 Person.objects.raw('SELECT * FROM some_other_table', translations=name_map)
That does not work.

Printing out the results from above gives me the following.


<RawQuerySet: 'SELECT id,first_name AS first, last_name AS last FROM rango_person'>

How do I convert this into a sql result, and or a dictionary?

The row above 
Reply all
Reply to author
Forward
0 new messages