0

I'm creating a form with UserCreationForm to create users but I need that the form just ask for username and email, and assign a default password to each account. So they can change it later.

Marco
  • 315
  • 1
  • 3
  • 13

1 Answers1

2

that?

class UserCreationForm(forms.ModelForm):


    class Meta:
        model = YourUserModel
        fields = ('email', 'username')

    def save(self, commit=True):
        # Save the provided password in hashed format
        user = super(UserCreationForm, self).save(commit=False)

        default_password = somefuntion() #Generate the default password

        user.set_password(default_password ) #Set de default password
        if commit:
            user.save()
        return user
Leandro
  • 2,217
  • 15
  • 18