- 数据库可变表和可变字段, 在查询中使用
**{role: request.user.username}
, 而 role 可以拼接并传入到查询语句中,非常方便
def _query_list_records(search_content, ddate, request, download_status, send_number):
start_date, end_date = parse_date(ddate)
role = get_role(request)
role = "samples__" + role
if download_status == [1]:
query_set = Report.objects.filter(
download_status__in=download_status, path__icontains=search_content, upload_date__gte=start_date,
upload_date__lte=end_date, samples__send_number__icontains=send_number, **{role: request.user.username})
else:
query_set = Report.objects.filter(
Q(download_status__isnull=True) | Q(download_status__in=download_status),
path__icontains=search_content, upload_date__gte=start_date, upload_date__lte=end_date,
samples__send_number__icontains=send_number, **{role: request.user.username})
return query_set
网友评论