有 3 个 class Class, Student, Homework 。 Class 对 Student 一对多, Student 对 Homework 一对多。
在 Class 中有 hybrid_property 返回 Class 中的 Homework 并集.
@hybrid_property
def homeworks(self):
return set([student.homeworks.all() for student in self.students.all()])
@homeworks.expression
def homeworks(cls):
return select([distinct(Homework)]).where(and_(Student.class_id == cls.id, Student.homework_id == Homework.id)).as_scalar()
现在想返回某个 Class 的 deadline 在 2016.11.11 的所有 homework 。
one_class.homeworks.filter(Homework.deadline == traget_date).all()
产生错误 homeworks Set object 没有 filter 方法。