0

我正在尝试搜索 ManyToMany 关系,但我做错了什么,我不确定它是什么

t = Teacher.objects.get(username=u.username)
var = list(Allowed.objects.filter(allowed=t))

这是我正在使用的课程:

class Allowed(models.Model):
  owner = models.ForeignKey(Teacher, related_name='allowed_teacher')
  reason = models.CharField(max_length=200, blank=True, null=True)
  allowed = models.ManyToManyField(Teacher, related_name='who_is_allowed', blank=True, null=True)

我该怎么做?

编辑: Teacher没有任何参考 Allowed

4

1 回答 1

1

你可以尝试这样做:

t = Teacher.objects.get(username=u.username)
var = t.allowed_set.all()
于 2013-04-16T14:52:14.267 回答