how do i write django subqueries?

Use annotate expression along with filter as,

from django.db import models

Book.objects \
    .annotate(avg_price=models.Avg('price')) \
    .filter(price__gt=models.F('avg_price'))

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top