Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有谁知道我为什么会收到这个错误?该属性all不在对象上
all
Subject.course_set.all()
如果我这样做是为了测试,它会起作用。
Course.objects.all()[0].subjects.all()
谢谢
Subject.course_set.all()没有意义。您必须在模型的实例而不是类上调用它,例如:
subject = Subject.objects.all()[0] #^ this is an instance subject.course_set.all()