美文网首页Django
2018-11-20 Django 数据库查询之奇技淫巧

2018-11-20 Django 数据库查询之奇技淫巧

作者: 多吃水果少吃肉 | 来源:发表于2018-11-20 10:38 被阅读0次
    • 数据库可变表和可变字段, 在查询中使用 **{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
    

    相关文章

      网友评论

        本文标题:2018-11-20 Django 数据库查询之奇技淫巧

        本文链接:https://www.haomeiwen.com/subject/qustqqtx.html