I have a pretty simple query and I need to add one field to get an average price grouped by benefit - I tried with ArrayAgg
but is not working.
properties = (
House.objects.filter(
# a lot of filters
).annotate(
prices=ArrayAgg(
HousePrice.objects.all().values("benefit").annotate(price_avg=Avg("price")).values("benefit_id" "price_avg")
),
)
)
more than one row returned by a subquery used as an expression
Relation with this model is big so it's why I want to just use the normal new query in annotate instead of going through all models between.
Any ideas on how to resolve that? I'm not sure if this way is good to use ArrayAgg
.