Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django, register user with first name and last name?

I'm using Django-Registration and the form just has 3 fields (Username, Email, Password, and Re-password), but why I can't add last name and first name??

In the Form all is fine but the User Model just accepts 3 arguments:

new_user = User.objects.create_user(username, email, password)

but why I can't do that:

new_user = User.objects.create_user(username, email, password, first_name ,last_name)

The Django Documentation doesn't say anything about just 3 arguments; all tutorials on the net just use 3 arguments...

Why?? Or how will I make use of first and last name?

like image 441
Asinox Avatar asked Sep 05 '09 01:09

Asinox


People also ask

Is Django username unique?

Even though the username field is marked as unique, by default it is not case-sensitive.

How do I create a signup page in Django?

Create Sign Up Form If you are new to Django form, refer Django form tutorial. Create forms.py file if it is not present and add the following class for the sign-up form. For creating sign up form, we can use the Django UserCreationForm . Create a view to process the signup data and save that data into the database.


2 Answers

I did it :

new_user = User.objects.create_user(username, email, password)
new_user.is_active = False
new_user.first_name = first_name
new_user.last_name = last_name
new_user.save()
like image 200
Asinox Avatar answered Oct 18 '22 22:10

Asinox


I know you found a way around, but this way below may also interest you. This is because it requires keywords arguments (which will be passed to the User's __init__ method). https://docs.djangoproject.com/en/3.2/ref/contrib/auth/#manager-methods

User.objects.create_user("user1", "[email protected]", "pwd", first_name="First", last_name="Last")
like image 34
Andre Miras Avatar answered Oct 18 '22 21:10

Andre Miras