Django: union of different queryset on the same model

前端 未结 2 961
日久生厌
日久生厌 2021-01-15 17:15

I\'m programming a search on a model and I have a problem.

My model is almost like:

class Serials(models.Model):
    id = models.AutoField(primary_ke         


        
2条回答
  •  梦谈多话
    2021-01-15 17:54

    You can make those four queries and then chain them inside your program:

    result = itertools.chain(qs1, qs2, qs3, qs4)
    

    but this doesn't seem to nice because your have to make for queries.

    You can also write your own sql using raw sql, for example:

    Serials.objects.raw(sql_string)
    

    Also look at this:

    How to combine 2 or more querysets in a Django view?

提交回复
热议问题