Is there a way to simplify this Django query?
- by Mark
accepted_bids = Bid.objects.filter(shipment__user=u, status='acc').select_related('shipment')
completed_shipments = []
for b in accepted_bids:
completed_shipments.append(b.shipment)
vehicles_shipped = []
for s in completed_shipments:
vehicles_shipped.extend(s.items.all())
In the end, I want a list of shipped vehicles. A vehicle is shipped if it's part of a shipment that's completed. A shipment is completed if it has an accepted bid.
I'd prefer not to iterate over the querysets thereby forcing a hit to the DB before its necessary... isn't there a way to get all the associated shipments from a list of bids, for example?