我想像这样更新 Django 模型中的数据:
video_id = request.POST['video_id']
# Get the form data and update the data
video = VideoInfoForm(request.POST)
VideoInfo.objects.filter(id=video_id).update(video)
return HttpResponseRedirect('/main/')
新数据由用户以表格形式提供。我想用 更新数据id=video_id
。这给了我以下错误:
update() takes exactly 1 argument (2 given)
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
115. response = callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/decorators.py" in _wrapped_view
25. return view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py" in view
68. return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py" in dispatch
86. return handler(request, *args, **kwargs)
File "/home/zurelsoft/virtualenv/videoManagement/VideoManagementSystem/video/views.py" in post
126. VideoInfo.objects.filter(id=video_id).update(video)
Exception Type: TypeError at /updateVideo/
Exception Value: update() takes exactly 1 argument (2 given)