Reputation: 1
I have created a form to update the existing user profile. But when i save the form it shows the error user already exists.
I used another approach by getting the user profile and then updating each field, but in that case each field has to be validated?
Any clue how to save the form as an update not as a new entry?
Upvotes: 0
Views: 103
Reputation: 1
I managed to get the answer, i imported the form to
u = User.objects.get(username = user_name)
user_form = UserEditForm(request.POST,instance=u)
user_form.save()
Upvotes: 0
Reputation: 6488
I suggest using UpdateView, one of Django's class-based-views for generic editing:
class django.views.generic.edit.UpdateView
A view that displays a form for editing an existing object, redisplaying the form with validation errors (if there are any) and saving changes to the object. This uses a form automatically generated from the object’s model class (unless a form class is manually specified).
Upvotes: 1