Django return select_related() filter as JSON -
i'm trying return object , it's relations json. works fine if this:
plant = plant.objects.get(slug=kwargs['slug']) return httpresponse(serializers.serialize("json", [plant]), content_type='application/json')
but wheni try select_related()
, no worky:
plant = plant.objects.select_related().filter(slug=kwargs['slug']) return httpresponse(serializers.serialize("json", [plant]), content_type='application/json')
is there way make django stop being lazy , and build object? know go ahead , render template , display output json, seems bit of kludge.
thanks helping!
i don't think has select_related()
when plant = [plant]
putting queryset
inside list in serializers/base.py when iterates on list finds queryset
instead of individual objects that's why error 'queryset' object has no attribute '_meta
but case
plant = plant.objects.get(slug=kwargs['slug']) return httpresponse(serializers.serialize("json", [plant]), content_type='application/json')
while iterating on list [plant]
gets object has _meta.local_fields
works you
i imagine work if this
plant = plant.objects.select_related().filter(slug=kwargs['slug']) return httpresponse(serializers.serialize("json", plant), content_type='application/json')
i passing queryset
serializer , not list contains queryset
.
i don't know if asking.
Comments
Post a Comment