i have two tables A and B, i need all the columns of both tables using django ORM(left join).
开发者_StackOverflow社区i am new bee to django and programming please help.
One way is to use the .values() callable on your query (though what you are asking is not very clear). This returns a querydict, rather than a queryset, but behaves more like a left join done SQL directly into the database - i.e returns the rows with null entries from table B.
Assuming table A has a foreign key to table B in the models file.
TableA.object.filter(your filters here).values(tableA__field1, tableA__field2 , ... \
tableB__field1, tableB__field2, etc).
https://docs.djangoproject.com/en/1.3/topics/db/aggregation/#values
精彩评论