MilletChili
2020-04-17 19:51:20 +08:00
一般的查询,我都是叫前端去拼的,虽然我就是那个前端
start_num = int(request.GET.get('start_num') or 0) # 起始数
get_num = int(request.GET.get('get_num') or 10) # 需求数
filters = request.GET.get('filters') # 筛选条件
sorts = request.GET.get('sorts') # 排序条件
want_fileds = request.GET.get('want_fileds') # 指定需要的字段
is_distinct = request.GET.get('is_distinct') # 是否去重
qset = model.objects.using(using_database).all()
if filters:
# print('筛选条件:',filters)
qset = filterHelper(filters, qset)
if sorts:
# print('排序条件:',sorts)
qset = qset.order_by(*sorts.split(','))
if is_distinct == 'yes':
qset = qset.distinct()
all_num = qset.count() # 总个数
qset = qset[start_num: start_num + get_num]
if want_fileds:
data_list = createSerializers(model, want_fileds.split(','))(qset, many=True).data
else:
data_list = Ser_L(qset, many=True).data
data = {'all_num': all_num, 'data_list': data_list}