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

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

    This recursive function concatenates array of querysets into one queryset.

    def merge_query(ar):
        if len(ar) ==0:
            return [ar]
        while len(ar)>1:
            tmp=ar[0] | ar[1]
            ar[0]=tmp
            ar.pop(1)
            return ar
    

提交回复
热议问题