Reputation: 260
I have a query
q = Product.objects \
.annotate(t=Subquery(Purchase.objects.filter(user=user)))
and when I do print(q.query)
I get the following exception:
{FieldError} Cannot resolve expression type, unknown output_field
What to do and why they can't resolve the expression type?
Upvotes: 0
Views: 575
Reputation: 7404
You need to use .values
, to select the field you want to annotate from user
q = Product.objects.annotate(t=Subquery(Purchase.objects.filter(user=user).values('pk')))
Upvotes: 1