使用Django的Q方法创建搜索条件:
name = request.GET.get('name') pages = request.GET.get('pages') operator = request.GET.get('operator') date1 = request.GET.get('date1') date2 = request.GET.get('date2') print('date1', type(date1), date2) conditions = [] if name: conditions.append(Q(account__contains=name)) if pages: conditions.append(Q(model_name=pages)) if operator: conditions.append(Q(operation=operator)) if date1: date1 = date1 + ' 00:00:00' conditions.append(Q(created_at__gte=date1)) if date2: date2 = date2 + ' 23:59:59' conditions.append(Q(created_at__lte=date2)) if conditions: intersection_query = Q(*conditions) res_info = OperationLog.objects.filter(intersection_query).order_by('-created_at')
标签:date1,date2,GET,交集,get,Django,搜索,conditions,append From: https://www.cnblogs.com/lytcreate/p/17639869.html