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

后端 未结 13 2431
猫巷女王i
猫巷女王i 2020-11-21 22:40

I am trying to build the search for a Django site I am building, and in that search, I am searching in 3 different models. And to get pagination on the search result list, I

13条回答
  •  别跟我提以往
    2020-11-21 23:34

    In case you want to chain a lot of querysets, try this:

    from itertools import chain
    result = list(chain(*docs))
    

    where: docs is a list of querysets

提交回复
热议问题