django filter多个不确定参数查询
1 kwargs = {} 2 condition = [] 3 if args.get('name'): 4 kwargs['name'] = args.get('name') 5 condition.append(ANNDistributionBatchTaskModel.batch_task_name.like(f"%{kwargs.get('name')}%")) 6 if args.get('pro_id'): 7 query_set = ANNTaskModel.query.filter(ANNTaskModel.type_id==args.get('pro_id')).first() 8 kwargs['task_id'] = query_set.id 9 condition.append(ANNDistributionBatchTaskModel.task_id == kwargs.get('task_id')) 10 if args.get('team_id'): 11 query_set=TeamMemberRelationshipModel.query.filter(TeamMemberRelationshipModel.team_id==args.get('team_id')).all() 12 user_list = [i.user_id for i in query_set] 13 kwargs['user_list'] = user_list 14 condition.append(ANNDistributionBatchTaskModel.user_id.in_(kwargs.get("user_list"))) 15 if args.get('status'): 16 kwargs['status'] = args.get('status') 17 condition.append(ANNDistributionBatchTaskModel.ann_status == kwargs.get('status'))
ANNDistributionBatchTaskModel.objects.filter(**kwargs)