Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

246
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!