I want to update data in Django model like this:
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/')
The new data is supplied by user in a form. I want to update data with id=video_id
. This gives me following error:
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)
The update
function only take keyword arguments, no generic arguments, that's why you get the update() takes exactly 1 argument (2 given)
error message.
Try:
VideoInfo.objects.filter(id=video_id).update(foo=video)
Where your models are :
class Video(models.Model):
...
class VideoInfo(models.Model):
foo = models.ForeignKey(Video)
...
Note that the doc linked in comment by lazy functor shows the signature of the update
function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With