我想更新在Django模型數據是這樣的:在以下情況下更新Django中的queryset?
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)
你究竟想要更新什麼? –
檢查此https://docs.djangoproject.com/en/dev/topics/db/queries/#updating-multiple-objects-at-once –
更新記錄其中id = video_id – pynovice