def home2 (request , long, lat):
for i in dat:
distance = math.sqrt(math.pow(i.latitud-lat, 2) + math.pow(i.long-long, 2) )
if distance < i.radius:
#Here the doubt begins because I have to take everything to JSON format to be sent
for data_format in data:
"days": data_format.days_of_works, "hour_ini":data_format.hour_init, "hour_end":data_format.hour_end,
return JsonResponse(array, safe=False)
I’m having a hard time how the array variable needs to be arranged to have a proper JSON format
No, I do not. I have to send all the objects of the item model that have the smallest distance to the radius. This is why I do the if distance <dat [i] .radius comparison.
If the condition is met, I add that item element to an array that I call data. But what I want is to send it ordered. This is the first element, this is the second and so on … And I think the best way to do it is using a JSON format
Let me guess, are you looking at the object you receive either by using the ‘alert’ dialog box or printing it in the console?