Rajesh Dhawan wrote:
> Hi Michael,
> 
>> How do I do something like this using Django Models?
>>
>>      SELECT name,birthdate FROM friends
>>        UNION
>>          SELECT name,birthdate FROM enemies
>>        ORDER BY birthdate, name;
>>
>> I can't find any reference in the Django docs to getting a UNION.
> 
> The Django ORM essentially maps one DB table to one Django model
> class. Since, in your example, friends and enemies are two different
> tables i.e. two different Django model classes, the above query is not
> possibly using the Django Model API. However, you can execute this
> query as well as other complex queries using by dropping in to raw
> SQL.
> 
> See this for an example:
> http://www.djangoproject.com/documentation/model-api/#executing-custom-sql

Thanks. Unfortunately doing it that way returns a list of tuples - a bit 
hard to work with.

Is there some way to get a "normal" (i.e. dictionary-like) response 
without having to resort to making my own connection with psycopg2?

Thanks,
Michael

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to