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

181
Views
How to fetch filtered data in Javascript from rest-framework

I need to filter the generals using their team ID. But I cannot implement it.

my code:

In choose.js:

document.addEventListener('DOMContentLoaded', function () {
      document.querySelectorAll('.card-title').forEach(team => {
        let team_id = parseInt(team.dataset.team)
        console.log(team_id)
        fetch(`/generals?team=${team_id}`)
            .then((response) => response.json())
            .then((result) => {
                console.log(result)
            })
        });
    })

In views.py:

class GeneralView(generics.ListAPIView):
    queryset = General.objects.all()
    serializer_class = GeneralSerializer
    filter_backends = [DjangoFilterBackend]
    filter_fields = ('team',)

In urls.py:

path('generals', views.GeneralView.as_view(), name='general_view')

In my browser console,. console.log(team_id) comes correctly but console.log(result) does not come correctly.

In one reload

One reload

In another reload Another reload

How to solve the problem?

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!