Took a little bit of digging to figure this one out. If you’re using a ModelForm along with django.contrib.auth.models.User (or a customized User model), you’ll want to use the instance that is sitting in the request rather than allowing the ModelForm to create a new instance.
To do this, simply override the get_form_kwargs method in the view:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|template_name = 'user.html'|
|form_class = UserForm|
|success_url = reverse_lazy('success')|
|kwargs = super(MyView, self).get_form_kwargs()|
|kwargs['instance'] = self.request.user|