from django.core import serializers
from django.core.paginator import Paginator
from django.http import JsonResponse
def search_monitorItem(request):
monitorItemInfos = []
pageNum = 0
total = 0
try:
monitorItemName = request.POST.get("monitorItemName", "")
xx_id = request.POST.get("xx_id", "")
monitorType = request.POST.get("monitorType", "")
pageSize = int(request.POST.get("pageSize", "5"))
# 多条件查询
queryset = models.MonitorItemManage.objects.all()
if monitorItemName:
queryset = queryset.filter(monitorItemName__contains=monitorItemName)
if monitorType:
queryset = queryset.filter(monitorType=monitorType)
if floatingPlatformId:
queryset = queryset.filter(xx_ID_id=xx_id)
# queryset = serializers.serialize('json', queryset)
# return JSONResponse({'data': queryset})
#
for monitorItem in queryset:
monitorItemInfo = {}
monitorItemInfo["monitorItemId"] = monitorItem.id
monitorItemInfo["itemIndex"] = monitorItem.itemIndex
monitorItemInfo["monitorItemName"] = monitorItem.monitorItemName
monitorItemInfo["monitorType"] = monitorItem.monitorType
monitorItemInfo["unit"] = monitorItem.unit
monitorItemInfo["updater"] = monitorItem.updater.userName
monitorItemInfo["updateTime"] = datetimeformat(monitorItem.updateTime)
monitorItemInfos.append(monitorItemInfo)
# 分页
page = Paginator(monitorItemInfos, pageSize)
pageNum = page.num_pages
total = page.count
except Exception as e:
print(e, e.__traceback__.tb_lineno)
return JsonResponse({"monitorItemInfos": monitorItemInfos, "pageNum": pageNum, "total": total})
django多条件查询
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 1:编辑views.py,增加内存查询的逻辑 导入Q from django.db.models import Q...
- 随着vue、react在实际开发中应运越来越广泛,前端们处理数据的需求越来越多。这篇文章就讨论一下轻量级列表的搜索...