[Answer]-Filter Child rows in a Django Queryset

1👍

You have to build the datastructure yourself. What you want is essentialy two queries and you cant fetch that in one call.

data = {"collection":None, "sales":[]}
for coll in Collection.objects.filter(sales__status="ACTIVE"):
   data["collection"] = coll
   for collsales in coll.collectionsales_set.filter(status="ACTIVE")
      data["sales"].append(collsales.collection)
👤RickyA

Leave a comment