12👍
✅
You need to used your variable circuits
circuits = Circuits.objects.filter(site_data__id=1)
for cm in circuits:
maintenances = cm.maintenance.all()
for maintenance in maintenances:
print(maintenance )
If you don’t define a related_name
, you can do:
circuits.circuitmaintenance_set.all() :
Source:stackexchange.com