Answer the question
In order to leave comments, you need to log in
Why can't I update model fields?
forms.py:
class FooForm(forms.ModelForm):
class Meta:
model = Foo
exclude = ['created']
class FooView(FormView):
success_url = '/some/url/'
template_name = 'some/template.html'
form_class = FooForm
model = Foo
def form_valid(self, form):
if 'foo' in self.request.session:
pk = self.request.session['foo']
foo = Foo.objects.get(pk=pk)
self.object = form.save(instance=foo)
else:
self.object = form.save()
self.request.session['foo'] = self.object.pk
return HttpResponseRedirect(self.get_success_url())
TypeError at /some/url
save() got an unexpected keyword argument 'instance'
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question