Json接收python:
{
"str_ini": "2020-06-05",
"fnsh_date": "2020-06-20",
}
我使用 str_ini 和 fnsh_date 作为参数来构建我的查询。
订单模型.py:
fservice = models.DateTimeField(db_column='FService') # (In DB this field is datetime)
ffinishservice = models.DateTimeField(db_column='FFinishService') # (In DB this field is datetime)
视图.py:
pedidoparams = request.data
start_date = pedidoparams.get("str_ini")
finish_date = pedidoparams.get("fnsh_date")
order = (
OrderModel.objects.values("zone__zone")
.filter(fservice__gte=fecha_inicio)
.filter(ffinishservice__lte=fecha_final)
.annotate(order_activate=Count("cctt__id"))
)
print("query: ", str(pedidos.query))
和 python 打印这个查询:
query: SELECT `zone`.`Zone` AS `Zone`, COUNT(`order`.`cctt_id`) AS `order_activate` FROM `order` INNER JOIN `zone` ON (`order`.`Zone_Id` = `zone`.`Id`) WHERE (`order`.`fservice` >= 2020-06-05 00:00:00 AND `order`.`ffinishservice` <= 2020-06-20 00:00:00) GROUP BY `zone`.`Zone`
我的问题是:为什么要在查询中添加小时、分钟和秒?如果只接收日期,是否有可能在查询中是:
... Where (`order`.`fservice` >= 2020-06-05 00:00:00 AND `order`.`ffinishservice` <= 2020-06-20 23:59:59)