[Fixed]-Django user registration where username becomes "firstname.lastname"

1👍

Override save method in SignUpForm

def save(self, commit=True):
    instance = super(SignUpForm, self).save(commit=False)
    instance.username = "%s.%s" %(self.cleaned_data['first_name'], self.cleaned_data['last_name'])
    if commit:
        instance.save()
    return instance

0👍

You could try something like:

my_data = dict(request.POST.iterlists())
my_data['username'] = my_data['firstname'] + '.' + my_data['lastname']

form = SignUpForm(my_data)

if form.is_valid():
            form.save()
...

Leave a comment