我尝试使用Django过滤器进行查询工作。有什么帮助吗?
tmp = TemporaryLesson.objects.filter(Q(expiration_date__gte=now()) | Q(expiration_date__isnull=True))
temporary_lessons = []
for t in tmp: # How to make this manual query works in the filter above?
for c in t.related_courses:
if c in student.my_courses:
temporary_lessons.append(t)
break
编辑: 模型变量
来自学生
my_courses = models.ManyToManyField(
'course.BaseCourse',
related_name='students',
through=CourseXStudent
)
来自TemporaryLesson
related_courses = models.ManyToManyField(
'course.BaseCourse',
related_name='temporary_lessons'
)