Tuesday, September 30, 2014

Re: Need example to implement sql (dictionary) translations

 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 
On Monday, September 29, 2014 1:11:51 PM UTC-4, robert brook wrote:
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)

You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2b6d8cd6-7c0b-41cd-bc95-e54837d6b732%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment