Json receiving python:
{
"str_ini": "2020-06-05",
"fnsh_date": "2020-06-20",
}
I use str_ini and fnsh_date as a parameter to build my query.
OrderModel.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)
Views.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))
And python print this query:
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`
My question is: why do you add hours, minutes and seconds to the query? In case of receiving only the dates, would it be possible that in the query it was:
... Where (`order`.`fservice` >= 2020-06-05 00:00:00 AND `order`.`ffinishservice` <= 2020-06-20 23:59:59)