Как объединить набор запросов django с помощью оператора AND & OR

Это мой код конкатенации, но он не работает. Как конкатенировать django queryset с помощью оператора AND & OR?

    sales_by_branch =  OrderItems.objects.values('order__entity__id').order_by('order__entity__id').annotate(total_amount=Sum('total_price')).filter(order__is_approved=True).filter(order__is_success=True)
    v=0
    subset=[]
    for product_id in product_id:
        product_id = int(product_id)
        product_code = ProductCodes.objects.values('flavour_id','product_id','quantity_id').filter(id=product_id)
        if product_code:
           for item in product_code:
               flavour_id =item['flavour_id']
               product_id =item['product_id']
               quantity_id =item['quantity_id']
               if v==0: 
                 sales_by_branch = sales_by_branch.filter(flavour_id=flavour_id,product_id=product_id,quantity_id=quantity_id)
               else:
                subset = OrderItems.objects.filter(flavour_id=flavour_id,product_id=product_id,quantity_id=quantity_id)
                ales_by_branch =  sales_by_branch  | subset 
        v=v+1 
    
Вернуться на верх