title: Django declare subquery for re-use?
body: <p>Is there a way to store a subquery in django the same way SQL DELCARE works?</p>
  <p>I've got multiple calculations using subqueries.
  I then reference these subqueries in further calculations.</p>
  <p>Problem is, once these subqueries are referenced, they &quot;run again&quot; and call another huge select query unnecessarily.</p>
  <p>Is there a way to call the query once then re use?</p>
  <p>Only stipulation is that this needs to be done in a single query using annotations.</p>
  <p>Example below - &quot;fo_val&quot; will be recalled further times;</p>
  <pre><code>annotations = {
      'order_val': Sum('containerorderitem__order_cost'),
  
      'fo_deposit_paid': Coalesce(CwhInvoice.objects.filter(
          container_ref=OuterRef('factory_order__ref_no'),
          add_cost_code=7
      ).values('container_ref').annotate(
          total=Sum('total_amount')
      ).values('total'), Value(0)),
  
      'fo_val': FactoryOrderItem.objects.filter(
          factory_order_id=OuterRef('factory_order_id')
      ).values('order_cost').annotate(sum=Func('order_cost', function='SUM')).values('sum'),
  
      'fo_deposit_pct': Cast((F('fo_deposit_paid') / F('fo_val')) * 100, FloatField()),
  }
  
  self.model.objects.annotate(**annotations).values(etc)
  </code></pre>