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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -