Guest User

Untitled

a guest
Jul 29th, 2012
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. Is there an alternative to raw sql query?
  2. class Teacher(models.Model):
  3. schools = models.ManyToManyField(School, db_table="schoolteachers", related_name='scteachers')
  4.  
  5. def get_teachers(self):
  6.  
  7. return ' , '.join(school.name for school in self.scteachers.all())
  8.  
  9. ', '.join(School.objects.filter(
  10. other_way_from_school_to_schoolteachers__teacher__pk=self.pk
  11. ).values_list('name', flat=True))
Advertisement
Add Comment
Please, Sign In to add comment