开发者

Django-ORM Left join with all columns of both tables

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜