Contribute Media
A thank you to everyone who makes this possible: Read More

Getting the most out of Django’s User Model

Description

DjangoCon US 2017 - Getting the most out of Django’s User Model by Julia M. Looney

Django’s User model is nice, but the fields it provides out of the box are minimal. We frequently need to associate our own custom data with a user, and luckily Django provides ways for us to add to its built-in User model. This talk will help novice Django developers understand which options are best when it comes to getting the most out of the Django User model.

I’ll start by talking about the built-in Django User model and what it has to offer.

Then I will identify scenarios when the User model might not be enough for a project, and why someone might want something with more flexibility. Then we’ll look at the different ways to get the most out of the Django User model. There are two main methods I’ll cover:

Extending the User model Creating a custom User model

Extending the User model:

Extending the User model is handy when you only need to add a few extra fields. There are two main ways to do this: using a proxy model, and using a OneToOneField. I will cover the pros and cons of each, and give examples for implementing each.

Creating a custom User model:

With this method, you can substitute Django’s default User model with your own. Though more complex, a custom User model is particularly useful when you need to uniquely identify users by email address instead of by username. I’ll go into a couple more scenarios where a custom User model would be helpful, and show examples of implementation.

Lastly, I will show how each method works with the default Django admin, and how they can be managed there.

https://2017.djangocon.us/talks/getting-the-most-out-of-djangos-user-model/

Details

Improve this page