0

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?

1 Answer 1

1

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')))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.