我正在尝试搜索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
答案 0 :(得分:1)
您可以尝试:
t = Teacher.objects.get(username=u.username)
var = t.allowed_set.all()