[Answer]-Django filter from within models

1👍

You can do this a little easier with django aggregates.

from django.db.models import Sum


class PeopleCount(models.Model):
   ...

   def totalPeopleByStop(self, stopname):
        return PeopleCount.objects.filter(StopID=stopname).aggregate(
            total_people_by_stop=Sum('Count'))['total_people_by_stop']

Leave a comment