【发布时间】:2013-10-02 10:00:44
【问题描述】:
我遇到了美味派的问题,但我找不到是什么原因造成的。没有答案的类似问题:Tastypie foreign key relationship throwing error
资源:
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
让我感到沮丧的是,它就像 2 天前一样工作。我添加了 1 个其他资源,而没有触及选择、用户或与模型相关的任何其他资源。我检查了最近的提交历史,并且资源没有受到影响。
【问题讨论】: