Add Fields From User Model to New User Registration Form?

Hi all,

Is it possible to add “Last name,” “First name,” and “Email address” to the default new user registration form and make them required fields? In addition, is it possible to add any of the three custom fields from the class I have written below to the new user registration form and potentially making them required? I don’t know why I’m having trouble finding an answer. It seems like you should be able add any field from the default user model to the new user form.

class AFRUser(models.Model):
    user = models.OneToOneField(User, blank=True, null=True, on_delete=models.SET_NULL)
    institution = models.CharField(blank=True, max_length=100)
    private_collector = models.BooleanField(default=False)
    dealer = models.BooleanField(default=False)

Current form:

Strictly speaking, you have not altered the standard User model - you have logically extended it by adding a related model. Therefore, when you generate a form from the User model, those are the only fields you’re going to get.

If you want fields from both the standard User model and your Profile model on the same page, you’re going to need to create the form yourself. It’s quite possible, although I’ve never tried this, that you might be able to access the existing standard User model form and then just extend it with your fields. Then, your view will need to process that form and save the appropriate fields in the proper objects.

Just keep in mind that with this structure, you’re not working with one User object. You’re working with two separate objects that just happen to be linked via a One-to-One relationship field.

Hi Ken,

I guess I’m not getting why Django has fields such as “last name,” “first name,” and “email address” in the standard user model, yet no easy way to expose them in a new user registration form. Otherwise, how are you supposed to get those fields filled out by a user?

FYI, I had success using the technique shared here: