[Answer]-How to force initial data into an instanciated django ModelForm?

0👍

Just change your user instance before passing it to the form. The data will not be saved unless you call user.save() explicitly.

👤jeyk

1👍

I know this is old and I don’t know if this is exactly what you were asking for, but this might help to someone else:

class UserForm(forms.ModelForm):

    def __init__(self, *args, **kwargs):
        kwargs['initial'] = {'username': 'whatever'}  # Override instance initial
        super().__init__(*args, **kwargs)
👤j4n7

Leave a comment