[Answer]-Django DB design Guidance

1👍

It’s a little unclear, are you asking how you would get the total count for pests in a specific trap? I.e.

trap = Trap.objects.get(name="Fly Trap")
pest = Pest.objects.get(common_name="House Fly")

total_pest_count = PestCount.objects.filter(
    reading__trap=trap,
    pest=pest
).aggregate(Sum('count'))

Untested, should work though. Aggregation docs page here.

Or are you wanting to change your database schema for another reason?

👤ptr

Leave a comment