Here is my model:
class Teacher(models.Model):
name = models.CharField(max_length=50)
subjects = models.ManyToManyField(Subject)
class Subject(models.Model):
name = models.CharField(max_length=50)
type = models.ForeignKey(SubjectType)
class SubjectType(models.Model):
name = models.CharField(max_length=50)
I want to do something like that in template:
{regroup subjects by subject.type}
{foreach subject_type}
#display all teachers for subject_type
Each subject has its teacher_set.
How can i union all teachers for a particular subject_type?
I think you can’t get this functionality from the template. However, you could do it in your view:
Now, you have a list of unique teachers in
my_teachersfor a particular SubjectType.EDIT: You could do this for every SubjectType object and pass the resulting list (of lists) to the template.