我正在开发一个 API,对于我的一个端点,我希望能够进行部分更新。
这里是美味的资源
class StoryResource(ModelResource):
authors = fields.ToManyField(SimpleAuthorResource, 'authors', full=True)
posts = fields.ToManyField(SimplePostResource, 'posts', full=True, blank=True)
cover_photo = fields.ForeignKey(PhotoResource, 'cover_photo', full=True)
class Meta:
queryset = Story.objects.all()
resource_name = 'story'
validation = ModelFormValidation(form_class=StoryForm)
authorization = Authorization()
allowed_methods = ['get', 'post', 'patch', 'put']
ordering = ['-created_ts']
def determine_format(self, request):
return "application/json"
我正在使用 POSTMAN 发出 PATCH 请求以更新 Story 模型中的字段。
它返回此错误:
{"error_message": "'Bundle' 对象不可迭代", "traceback": "Traceback (最近一次调用最后一次):\n\n 文件\"/usr/local/lib/python2.7/dist-packages/ sweetpie/resources.py\",第 192 行,在包装器中\n response = callback(request, *args, **kwargs)\n\n File \"/usr/local/lib/python2.7/dist-packages/ sweetpie/resources.py\",第 406 行,在 dispatch_detail\n return self.dispatch('detail', request, **kwargs)\n\n File \"/usr/local/lib/python2.7/dist- packages/tastypie/resources.py\",第 427 行,在 dispatch\n response = method(request, **kwargs)\n\n File \"/usr/local/lib/python2.7/dist-packages/tastypie /resources.py\",第 1332 行,在 patch_detail\n self.update_in_place(request, bundle, deserialized)\n\n File \"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\",第 1345 行,在 update_in_place\n self.is_valid(original_bundle, request)\n\n 文件 \"/usr/local/lib/python2.7/dist-packages /tastypie/resources.py\",第 991 行,在 is_valid\n 中错误 = self._meta.validation.is_valid(bundle, request)\n\n 文件 \"/var/www/novella-django/novella/novella/ api/validation.py\",第 55 行,在 is_valid\n data[field] = self.uri_to_pk(data[field])\n\n File \"/var/www/novella-django/novella/novella/api /validation.py\",第 29 行,在 uri_to_pk\n for one_uri in uris:\n\nTypeError: 'Bundle' object is not iterable\n"}在 is_valid\n 错误 = self._meta.validation.is_valid(bundle, request)\n\n 文件 \"/var/www/novella-django/novella/novella/api/validation.py\",第 55 行,在is_valid\n data[field] = self.uri_to_pk(data[field])\n\n 文件 \"/var/www/novella-django/novella/novella/api/validation.py\",第 29 行,在 uri_to_pk \n for one_uri in uris:\n\nTypeError: 'Bundle' object is not iterable\n"}在 is_valid\n 错误 = self._meta.validation.is_valid(bundle, request)\n\n 文件 \"/var/www/novella-django/novella/novella/api/validation.py\",第 55 行,在is_valid\n data[field] = self.uri_to_pk(data[field])\n\n 文件 \"/var/www/novella-django/novella/novella/api/validation.py\",第 29 行,在 uri_to_pk \n for one_uri in uris:\n\nTypeError: 'Bundle' object is not iterable\n"}
我不太确定出了什么问题,而且我似乎在其他任何地方都找不到这个错误。