django - Trying filter query depending on a method of a related model -
class course(models.model): def is_active(self): return self.enroll_set.count()>0 class courseevent(models.model): course = models.foreignkey(course)
i want find events
point active courses. like:
events = courseevent.objects.filter(course.is_active=true)
thank you
the answer here: https://docs.djangoproject.com/en/dev/ref/models/querysets/#annotate
you make annotation, it'll filterable field.
it may this:
courseevent.objects.annotate(is_active=count('course__enroll')).exclude(is_active=0)
Comments
Post a Comment