我有一个模型,有2个外国文件指向同一个模型:
class Student(models.Model):
old_school = model.ForeignField(school)
new_school = model.ForeignField(school)
我想找到old_school的学生!= new_school。我试过这些:
Student.objects.all().exlude(old_school = new_school)
Student.objects.all().exlude(self.old_school = self.new_school)
但它们都不起作用。似乎模型经理不能参考new_school。有什么方法可以做这样的查询吗?或者我必须在python代码中手动检查不相等:
if student.old_school != student.new_school:
s_list.append(student)