But some how the there is no consistency in output. some time you will see in console there is two consecutive "inside post" and some time some time you will see one time two time consecutive "after save method" printed in console. Data also saved in database there no consistency. One solution I can think of before same user was sending many post request at same time by clicking single button now I am thinking after clicking button first request should go and after frontend got respond second request should send post request and so on. If you have better approach please suggest
@csrf_exempt
def product_rest(request,pk):
product=Product.objects.get(pk=pk)
if request.method == "POST":
status = True
code = 200
message = ""
data = []
print("inside post")
parsed_data=json.loads(request.body)
print("parsing data == ", parsed_data)
try:
db_time = json.loads(product.time)
print("old data ==",db_time)
db_time.append(parsed_data)
db_time_tostring=json.dumps(db_time)
print("after adding data == ", db_time_tostring)
product.time=db_time_tostring
product.save()
print(" after save method == ", product.time)
message = "Order status created"
except:
status = False
code = 500
message = "Internal server error"
return JsonResponse({
"status": status,
"code": code,
"message": message,
"data": data
})