0
votes

How would you go about modifying the fields in the Django User Model to be required?

I'd like a User to require that a name and email address be entered at the time of creation, but I'm not sure how to go about doing this. Furthermore, I also want to be able to add fields to the User model. Looking around, I'm not sure what the best way to do this would be. There seem to be different schools about actually extending the User model or doing it through a one-to-one relationship.

1

1 Answers

3
votes

You can set the required fields in your registration form (all fields will be required unless your specify required=False)

As for extending the User model, I'd recommend taking advantage of the AUTH_PROFILE_MODULE setting as described by James Bennett in this tutorial: http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-model/

Basically you set AUTH_PROFILE_MODULE to your user profile model, and this allows you to access your user as follows:

# In settings.py
AUTH_PROFILE_MODULE = 'myapp.UserProfile' # Assumes your user profile model is called UserProfile

# In your view
u = User.objects.get(pk=1)
u.get_profile().home_address

# In your template
u.get_profile.home_address

http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-model/