Python Django:嵌套的OuterRef无法访问祖父母';身份证
试图使用嵌套子查询中的OuterRef访问FeeCount模型的id,但不是直接父查询。投掷:Python Django:嵌套的OuterRef无法访问祖父母';身份证,python,django,rest,Python,Django,Rest,试图使用嵌套子查询中的OuterRef访问FeeCount模型的id,但不是直接父查询。投掷: ValueError:此查询集包含对外部查询的引用,只能在子查询中使用。 first_unpaid_fee_schedule_instalment = Subquery(FeeScheduleInstalment.objects \ .annotate( total_balance = Subquery( FeeInstalmentTransaction
ValueError:此查询集包含对外部查询的引用,只能在子查询中使用。
first_unpaid_fee_schedule_instalment = Subquery(FeeScheduleInstalment.objects \
.annotate(
total_balance = Subquery(
FeeInstalmentTransaction.objects.filter(
account_id=OuterRef(OuterRef('id')), # not working: need grand-parent's id here
instalment__schedule=OuterRef('id'), #working: parent's id
) \
.values('balance') \
.annotate(total_balance=Sum('balance')) \
.values('total_balance')
)
) \
.values('id')[:1]
)
fee_accounts_with_first_unpaid = FeeAccount.objects \
.annotate(
first_unpaid_schedule = first_unpaid_fee_schedule_instalment,
)
通过将django版本更新为3.1解决了此问题 以前是2.5。可能是版本错误