Matt M
Matt M

Reputation: 149

how do i get the string inside the charfield in django?

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

Answers (2)

karthikr
karthikr

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

mipadi
mipadi

Reputation: 410792

Assuming person is a Person instance:

name = person.name
email = person.email 

Upvotes: 1

Related Questions