我的问题是如何在Django中使用django-filters进行以下查询?
Schedule.objects.filter(Q(room_id__number__icontains=get_request['room']) | \
Q(room_id__name__icontains=get_request['room']), \
(Q(subject_id__full_name__icontains=get_request['subject']) | \
Q(subject_id__short_name__icontains=get_request['subject'])),
(Q(teacher_id__name__icontains=get_request['teacher']) | \
Q(teacher_id__short__icontains=get_request['teacher']))
)
到目前为止我所拥有的内容如下。问题是这些字段没有room_id__name, teacher_id__short, subject_id__short_name
。我只是想制作主题或请求,但不知道如何使用django-filters
class ScheduleFilter(django_filters.FilterSet):
room = django_filters.CharFilter(name='room_id__number', lookup_type='icontains')
subject = django_filters.CharFilter(name='subject_id__full_name', lookup_type='icontains')
teacher = django_filters.CharFilter(name='teacher_id__number', lookup_type='icontains')
class Meta:
model = Schedule
fields = ['room', 'subject', 'teacher']