Note that there are some explanatory texts on larger screens.

plurals
  1. POTastypie foreign key relationship throwing error
    text
    copied!<p>I have a Photo application setup using tasty pie. I tried adding functionality to let users like a photo, using a PhotoLike model and resource. I thought it would be a simple addition, but I have been pulling my hair out for two days now :(</p> <p>I am getting the error below </p> <pre><code>{ "error_message": "'dict'objecthasnoattribute'obj'", "traceback": "Traceback(mostrecentcalllast):\n\nFile\"/env/lib/python2.7/site-packages/tastypie/resources.py\",line195,inwrapper\nresponse=callback(request,*args,**kwargs)\n\nFile\"/tastypie/resources.py\",line426,indispatch_list\nreturnself.dispatch('list',request,**kwargs)\n\nFile\"/env/lib/python2.7/site-packages/tastypie/resources.py\",line458,indispatch\nresponse=method(request,**kwargs)\n\nFile\"/env/lib/python2.7/site-packages/tastypie/resources.py\",line1320,inpost_list\nupdated_bundle=self.obj_create(bundle,**self.remove_api_resource_names(kwargs))\n\nFile\"/Users/bilal/Development/GWala/webapp/Guidewala/photowala/api.py\",line172,inobj_create\nreturnsuper(PhotoLikeResource,self).obj_create(bundle,user=bundle.request.user)\n\nFile\"/env/lib/python2.7/site-packages/tastypie/resources.py\",line2083,inobj_create\nbundle=self.full_hydrate(bundle)\n\nFile\"/env/lib/python2.7/site-packages/tastypie/resources.py\",line893,infull_hydrate\nsetattr(bundle.obj,field_object.attribute,value.obj)\n\nAttributeError:'dict'objecthasnoattribute'obj'\n" </code></pre> <p>}</p> <p>My model and resource is setup as follow:</p> <pre><code>class PhotoLike(TimeStamp): user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True) photo = models.ForeignKey(Photo, null=True, blank=True) class Meta: unique_together = ("user", "photo") def __unicode__(self): return 'like' </code></pre> <p>And my Resource is setup as follows</p> <pre><code>class PhotoLikeResource(ModelResource): photo = fields.ForeignKey(PhotoResource, 'photo', null=True, blank=True) class Meta: queryset = PhotoLike.objects.all() authorization = DjangoAuthorization() resource_name = 'photo_like' always_return_data = True def obj_create(self, bundle, **kwargs): return super(PhotoLikeResource, self).obj_create(bundle, user=bundle.request.user) </code></pre> <p>Any advice on what I am doing wrong or what the error is referring too would be greatly appreciated!</p> <p>Thanks for your time and help :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload