1
我遇到了tastypie的问题,我无法找到是什么原因造成的。无答案类似的问题:Tastypie foreign key relationship throwing errorTastypie外键关系'字典'对象没有属性'obj'
资源:
class VoteResource(ModelResource):
choice = fields.ToOneField(ChoiceResource, 'choice', full=True)
user = fields.ToOneField(UserResource, 'user')
class Meta:
queryset = Vote.objects.all()
resource_name = 'vote'
'''...'''
always_return_data = True
filtering = {
'id': ALL,
'user': ALL_WITH_RELATIONS,
'choice': ALL_WITH_RELATIONS
}
def hydrate(self, bundle):
bundle.obj.user = bundle.request.user
return bundle
用于创建对象请求有效载荷:
{
"choice": "/api/v1/choice/210/"
}
(用户正在越来越通过水合物自动添加)。在full_hydrate
的ressources.py中抛出异常。根据Django控制台我的对象正在正确加载。
内tastypie线造成这是
setattr(bundle.obj, field_object.attribute, value.obj) # value obj is the evil one
什么杀了我的,它的工作就像3天前。我添加了1个其他资源,但未触及选择,用户或与该模型相关的任何其他资源。我检查了最近的提交历史记录,并且资源未被触及。