+1

AttributeError: 'dict' object has no attribute 'objects' please help a friend

I have been on this for almost 12hrs and I don't seem to many any headway at finding what i am not doing right. Error message I keep getting is: Error Message k = fixture.objects.filter(api_football_fixture_id=id_fixture) AttributeError: 'dict' object has no attribute 'objects' views.py def get_score(request): if request.is_ajax() and request.POST: data = request.POST.get('date') score = get_scores(data) respond = {'message': 'operation successful'} return HttpResponse(json.dumps(respond), content_type='application/json') else: raise Http404 def get_scores(date): fixture = api_request(f'fixtures/date/{date}') for b in fixture['api']['fixtures']: if b['goalsHomeTeam'] is not None: home_score = str(b['goalsHomeTeam']) else: home_score = '' if b['goalsAwayTeam'] is not None: away_score = str(b['goalsAwayTeam']) else: away_score = '' extra_time = b['score']['extratime'] penalty = b['score']['penalty'] half_time = b['score']['halftime'] full_time = b['score']['fulltime'] match_status = b['status'] api_football_home_team_id =b['homeTeam']['team_id'] api_football_away_team_id =b['awayTeam']['team_id'] api_football_league_id = b['league_id'] id_fixture= b['fixture_id'] k = fixture.objects.filter(api_football_fixture_id=id_fixture) print(k)

11/18/2019 2:40:05 PM

Kayode Adetayo

4 Answers

New Answer

+5

From your views.py do{ if request.method == "POST": if request.is_ajax() } and it's either you do this data = request.POST["date"] Or data = form.cleaned_data.get("date") Use the same method to make reffrence to the score variable. Also, this doesn't matter but you should raise 201 error instead of 404 since that's strictly for (page not found).

+2

Mirielle🐶 [Inactive] i am able to make api calls with data value. just having issue with the queryset. i tried the suggestion. i am still getting the same error. thanks

+2

If the problem is from the queryset, then the code you provided above is not useful to solve the problem.. Queryset should be from the model.py files. also request.POST("date") as used above could cause the same error

+1

Mirielle🐶 [Inactive] I am finally able to trace it. one of the variables shares same name with my model. Everything works fine now. Thanks