他のいくつかの質問を確認したところ、私のtastypieリソースは次のようになるはずです:
class MultipartResource(object):
def deserialize(self, request, data, format=None):
if not format:
format = request.META.get('CONTENT_TYPE', 'application/json')
if format == 'application/x-www-form-urlencoded':
return request.POST
if format.startswith('multipart'):
data = request.POST.copy()
data.update(request.FILES)
return data
return super(MultipartResource, self).deserialize(request, data, format)
class ImageResource(MultipartResource, ModelResource):
image = fields.FileField(attribute="image")
それが間違っているかどうか教えてください。
上記が正しいと仮定して、私が得られないのは、リソースに何を渡すかです。ファイル入力は次のとおりです。
<input id="file" type="file" />
バックボーン モデル img がある場合、画像を何に設定すればよいですか?
img.set("image", $("#file").val()); // tastypie doesn't store file, it stores a string
img.set("image", $("#file").files[0]); // get "{"error_message": "'dict' object has no attribute '_committed'" ...
ajax経由でtastypieにファイルをアップロードできるように、バックボーンの「画像」属性を何に設定すればよいですか?