my models:
class Course(models.Model):
...
class Section(models.Model):
course = models.ForeignKey(Course, on_delete=models.CASCADE, related_name='sections')
...
class SubSection(models.Model):
section = models.ForeignKey(Section, on_delete=models.CASCADE, related_name='subsections')
registration_required = models.BooleanField(default=True)
now I want to know if less than 5 subsections of a course are registration_required = False
. something like:
def validate(self, attrs):
course = self.instance
if course.sections.subsections.filter(registration_required=False).count() < 5:
# do something ...
what is the best way to do that ??