[Answered ]-Django SetPasswordForm and AdminPasswordChangeForm

2👍

Use the existing form. Overide the view’s get_form_kwargs method to pass the expected arguments to the form, instead of changing the __init__ method, which will break other things.

In order to save the password, you need to override the form_valid method and call form.save().

For create and update views, you don’t always need to override form_valid, because the default behaviour is to save the form and redirect. For FormView, the default behaviour is simply to redirect, so you do have to override it to get it to do anything useful.

class SetPasswordView(FormView):
    form_class = AdminPasswordChangeForm
    template_name = 'set.html'
    success_url = '/thanks/'

    def get_form_kwargs(self):
        kwargs = super(set, self).get_form_kwargs()
        kwargs['user_to_update'] = the user
        return kwargs

    def form_valid(self, form):
        form.save()
        return super(SetPasswordView, self).form_valid(form)

Leave a comment