1from django.db.models import OuterRef, Subquery, Count, Min
2
3subquery = Product.objects.filter(bc_sku=OuterRef('bc_sku')).values('bc_sku')
4 .annotate(dup_count=Count('*'), min_price=Min('product_price'))
5Product.objects.filter(product_type='good')
6 .annotate(dup_count=Subquery(subquery.values('dup_count')),
7 min_price=Subquery(subquery.values('min_price')))