[Answer]-Update record using model form in django

1👍

The error is probably related to the inconsistent behavior of the form wrt model. Since, the database stores the OneToOneField as integer and CharField as varchar.

You don’t have to override the form init method. You could do it directly with the initial argument.

form = EditBasicDetailsForm(initial = {'username' : request.user)

Update:

In your view code I would suggest you to properly intend you HttpResponseRedirect statement. Otherwise, if the form is in valid it won’t display it again.

if form.is_valid():
          form.save()
          return HttpResponseRedirect('/myprofile/')

Leave a comment