【发布时间】:2020-11-13 03:40:08
【问题描述】:
我正在 React 中创建一个表,从我的 Django DB 中获取一些数据。
它有过滤器,如果需要,我希望他们调用 API 以获取结果。
问题是我必须复制很多行,而我很确定有更好的方法来做到这一点。
以下是部分代码:
if ss_value and not es_value and not iv_value and not timestamp:
queryset = DailyReport.objects.all().filter(station_departure=ss_value)
elif not ss_value and es_value and not iv_value and not timestamp:
queryset = DailyReport.objects.all().filter(station_arrival=es_value)
elif not ss_value and not es_value and iv_value and not timestamp:
queryset = DailyReport.objects.all().filter(is_virtual=iv_value)
elif not ss_value and not es_value and not iv_value and timestamp:
queryset = DailyReport.objects.all().filter(
Q(timestamp__range=(min_dt, max_dt)) | Q(upload_timestamp__range=(min_dt, max_dt)))
logger.debug(queryset)
elif ss_value and es_value and not iv_value and not timestamp:
queryset = DailyReport.objects.all().filter(station_departure=ss_value, station_arrival=es_value)
elif ss_value and not es_value and iv_value and not timestamp:
queryset = DailyReport.objects.all().filter(station_departure=ss_value, is_virtual=iv_value)
它会一直持续下去。
你有什么更清洁的方法吗??
谢谢你:)
【问题讨论】:
标签: django django-queryset django-orm