这是我的资源:
class ImageResource(ModelResource):
album = fields.ForeignKey(AlbumResource, 'album')
upload_by = fields.ForeignKey(UserResource, 'upload_by')
class Meta:
always_return_data=True
filtering = {
"album": ('exact',),
}
queryset = Image.objects.all()
cache = SimpleCache(timeout=100)
resource_name = 'image'
authorization = ImageAuthorization()
class ImageAuthorization(Authorization):
def read_list(self, object_list, bundle):
# This assumes a ``QuerySet`` from ``ModelResource``.
userprofile = UserProfile.objects.get(user = bundle.request.user)
album = Album.objects.filter(family=userprofile.family)
return object_list.filter(album__in=album)
当我尝试在视图中使用 ImageResource 时,例如:
@csrf_exempt
def upload(request):
if request.method == 'POST':
if request.FILES:
uploadedfile = request.FILES
file = uploadedfile['item']
album = Album.objects.get(pk=int(request.POST['album_id']))
img = Image(
album = album,
name = file.name,
src=file,
upload_by = request.user,
)
# img.save()
ir = ImageResource()
uploaded_img = ir.obj_get(src=file)
print uploaded_img
return HttpResponse('True')
这总是会出现错误说
obj_get() takes exactly 2 arguments (1 given)
我的代码有什么问题???以及如何获取刚刚上传的图片的资源