Reputation: 149
I'm trying to create a user in my model by calling the create_user function but I want it to have properties of what the user enters into my model. How do I do this?
This is what I have:
class Person(models.Model):
#basic information
name = models.CharField(max_length=50)
email = models.CharField(max_length=50, unique=True)
phone_number = PhoneNumberField(unique=True)
# FIX THIS!
user = User.objects.create_user(name, email, phone_number)
Upvotes: 0
Views: 807
Reputation: 99650
Looking at the definition.
The signature of create_user
is:
def create_user(self, username, email=None, password=None, **extra_fields)
username
is a required field
This has to be done in your view -
user = User.objects.create_user(first_name=name, last_name='', email=email, username=username)
Upvotes: 2
Reputation: 410792
Assuming person
is a Person
instance:
name = person.name
email = person.email
Upvotes: 1