Аннотировать: Передача параметра в подзапрос

У меня есть следующий набор запросов:

result = model_a.union(model_b)

У result есть такие поля:

 (`user`, `date`)

Можно ли передать поле date в поле Subquery следующим образом?

result.annotate(running_amount = Subquery(
                                  Model_C.objects.filter( 
                                                  Q(model_c__date__lt=('date') # <--- Pass date here
                                                    )
                                                 .aggregate(Sum('amount'), 0))['amount'] )
                                  output_field=IntegerField()
                                  ))

В соответствии с приведенной выше реализацией, возникает следующая ошибка:

... raise FieldError('Related Field got invalid lookup: {}'.format(lookup_name)) django.core.exceptions.FieldError: Related Field got invalid lookup: date_lt

Вопросы:

  1. Is it possible to pass the fields from the ‍‍‍result‍‍ to Subquery in order to filtering?
  2. Is there another way?
Вернуться на верх