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

248
Visualizações
Field 'id' expected a number but got <SimpleLazyObject: <User: username>>

I have been stuck on this error for some time and I can't wrap my head around the problem or what it even means.

I found some answers but none really solved my issue.

Here is a brief desciption of what I do:

In Javascript, I call this function with an int as a parameter such as:

function follow (user_id) {
    // retrieves post for current selection
    fetch(`/follow/${user_id}`, {
        method: 'PUT',
        body: JSON.stringify({
            follow: true
        })
    })
}

My url path, from url.py, is as follow:

path('follow/<int:user_id>', views.follow, name="follow")

finally, in views.py, this function is called:

def follow(request, user_id):

    user = User.objects.get(id = user_id)

    if request.method == "PUT":
        data = json.loads(request.body)
        if data.get("follow") is not None:
            followed = Followed(
                user_id = user.id,
                followed_by_id = request.user, 
                )

        followed.save()
        return HttpResponseRedirect(reverse("index"))

    else:        
        return HttpResponseRedirect(reverse("index"))

I have tried a few different approaches such as removing the .value but I keep getting the following error:

Field 'id' expected a number but got <SimpleLazyObject: <User: username>>

I check along the way and the ID is an int all the way until it is passed to the model to be saved.

I am using the abstractUser model.

Let me know if more information is needed.

Kind regards,

about 4 years ago · Juan Pablo Isaza
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