Prometheus
Prometheus

Reputation: 33655

Django Query Set into json object

Below I'm trying to get a query make is a json object, so that in my template using jQuery I can loop over it.

My View

from django.core import serializers
objectQuerySet = Recipient.objects.filter(incentiveid=incentive).values("mobile", "countryid")
data = serializers.serialize("json", objectQuerySet)

return render_to_response('smssend.html', context_instance=RequestContext(request))

I'm getting the following error.

Non-model object (<type 'dict'>) encountered during serialization

Request Method: 

why?

Upvotes: 0

Views: 1384

Answers (1)

allergic
allergic

Reputation: 392

#values() "returns dictionaries when used as an iterable" - https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.values

I think you need python's json#dumps(dict) here

Upvotes: 2

Related Questions