7
私はエラーRelated Field has invalid lookup: year
を持って次のクエリジャンゴ:関連フィールドが無効引き
User.objects.filter(student_attending__studentclasshistory__year=2011)
を実行しようとすると、私は次のモデルに
class SchoolClass(models.Model):
id = models.AutoField(primary_key = True)
class_name = models.TextField()
level = models.IntegerField()
taught_by = models.ManyToManyField(User,related_name="teacher_teaching",through='TeachSubject')
attended_by = models.ManyToManyField(User,related_name='student_attending',through='StudentClassHistory')
def __unicode__(self):
return self.class_name
class Meta:
db_table = 'classes'
class StudentClassHistory(models.Model):
student = models.ForeignKey(User)
year = models.IntegerField(default=datetime.date.today().year)
semester = models.IntegerField()
attended_class = models.ForeignKey(SchoolClass)
class Meta:
db_table = 'student_class_history'
を持っています。それは奇妙です。なぜなら私は年を省略し、利用可能なフィールドはCannot resolve keyword '' into field. Choices are: attended_class, id, semester, student, year
です。
これはどうですか?
また、through
というモデル属性では、related_name
を削除できますか?
それを説明bahhを、。ありがとう。別のqns:私はフィルタを入力した場合(student_attending__schoolclasshistory = ...)私は私の質問で、つまりschoolclasshistoryのエントリの数に比例して繰り返される用語を取得します。しかし、フィルター(schoolclasshistory = ..)は良いです。なぜこれはそうですか? – goh