Tastypie外键关系抛出错误

时间:2013-08-05 05:00:40

标签: django tastypie

我使用美味馅饼设置了Photo应用程序。我尝试使用PhotoLike模型和资源添加功能,让用户喜欢照片。我认为这将是一个简单的补充,但我现在已经把头发拉了两天:(

我收到以下错误

{
"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"

}

我的模型和资源设置如下:

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'

我的资源设置如下

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)

对于我所做的错误或错误所引用的任何建议都将不胜感激!

感谢您的时间和帮助:)

0 个答案:

没有答案