Django query: Combine two queryset in django
employees = Employee.objects.all()
staff = Staff.objects.all()
Now I want to combine these two queryset, any good way to do that? Thanks 开发者_Python百科for your help!
If both models inherit from the same superclass, you'd better query the superclass, and use the OneToOne automatic accessors to the subclasses to filter the query.
On the other side, if the two models are unrelated at the database level there is no easy way to (filter|offset|limit) both queries, neither in pure SQL. Just make them into lists and use them as they are.
精彩评论