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

后端 未结 13 2412
猫巷女王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:27

    Try this:

    matches = pages | articles | posts
    

    It retains all the functions of the querysets which is nice if you want to order_by or similar.

    Please note: this doesn't work on querysets from two different models.

提交回复
热议问题