a_igin

subquery

Sep 16th, 2020
643
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.             company_additions_subquery = CompanyAddition.objects.filter(
  2.                     related_order_additions__order_product__product=OuterRef('product'))
  3.  
  4.             subquery = Subquery(company_additions_subquery.values('pk'))
  5.  
  6.             order_products = OrderProduct.objects.filter(
  7.                 order=data['order'],
  8.                 product=data['product']).annotate(
  9.                 order_product_additions=subquery)
  10.             for order_product in order_products:
  11.                 print(order_product)
  12.                 print(order_product.order_product_additions)
RAW Paste Data