filter using Q object with dynamic from user?

后端 未结 1 1283
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-09 06:46

In my views.py I have a method:

#......
def get_filter_result(self, customer_type, tag_selected):
        list_customer_filter=[]
        customers_filter =          


        
相关标签:
1条回答
  • 2020-12-09 07:23

    This works for both single and multiple conditions:

    idseq = request.POST['tag'].split(',')
    tag_qs = reduce(operator.or_, (Q(tag__id=x) for x in idseq))
    Customers.objects.filter(..., tag_qs)
    
    0 讨论(0)
提交回复
热议问题