Ilya
Ilya

Reputation: 363

Transmitting JSON Django

I have a request for a model

paymentparking = paidparking.objects.filter(expirationdate__range=(startdate, enddate))

I need to take 2 fields from the request and pass them to JS I send it via

return JsonResponse({'price': paymentparking.price,'expirationdate':paymentparking.expirationdate})

But I get an error АttributeError: 'QuerySet' object has no attribute 'price'

Upvotes: 0

Views: 31

Answers (1)

Guillaume
Guillaume

Reputation: 2006

You're trying to access an attribute of your Model (paidparking) but you are actually using the result of the queryset. If you want to have the list of expirationdate and price, use values.

paymentparking = paidparking.objects.filter(expirationdate__range=(startdate, enddate)).values('expirationdate', 'price')
return JsonResponse(dict(paymentparking))

Upvotes: 2

Related Questions