Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

128
Visualizações
same user Sending multiple post api request at same time and we are trying to add new data with old data in database

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
        })
about 4 years ago · Santiago Gelvez
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda