Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

252
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda