I have following models setup in Django 1.3. I have School and Teacher with many-to-many relationship.
class Teacher(models.Model):
schools = models.ManyToManyField(School, db_table="schoolteachers", related_name='scteachers')
Now, I have a search view which displays school information. At present, to display teachers for each school, I have a function in School model,
def get_teachers(self):
return ' , '.join(school.name for school in self.scteachers.all())
So, if we are displaying 50 schools, we are making 50 queries which I want to avoid. I was thinking of using raw_query. But can something else be done?
thanks