我正在尝试使用通过外键引用的对象的属性来过滤掉对象
>>> sa = Survey.objects.all()
>>> sa.filter(student.gender='M')
File "<console>", line 1
SyntaxError: keyword can't be an expression
有不同的方法吗?列出针对男学生的调查?
我的模特看起来像这样:
class Student(models.Model):
# ...
GENDER = (
('M','Male'),
('F', 'Female'),
)
gender = models.CharField(max_length=1, choices=GENDER)
class Survey(models.Model):
student = models.ForeignKey(Student)
# ...