User Diversity1:41 with Kenneth Love
Not all user models are identical. Some sites need some more specific fields and information. What are your options when you need to hold a date-of-birth?
The docs for creating custom users models are really good and you should read through them even if you're going to use the standard user model. You'll see a bit more about how all of the pieces fit together.
[MUSIC] 0:00 Depending on your needs Django offers you a couple of different 0:04 ways to get custom users. 0:07 Here are the main ways that you'll generally customize your users. 0:09 You can do it through an extra model. 0:12 This is the original Django way of customizing users 0:14 you create a new model that has a one to one relationship to Django's User Model. 0:17 This model holds extra non-critical information about your users. 0:21 This is where you store their avatar or notification settings. 0:23 Since these are one to ones though, you want to make sure and 0:28 create one even if it's blank when you make a new user. 0:30 For extra fields, sometimes you just need to attach a new field or two to a user. 0:33 Maybe you want to record that they accepted your Terms of Service or 0:38 you need to hold a phone number. 0:41 You can extend the abstract user model from Django's off module, and 0:42 add your special new fields. 0:46 This model is exactly the same as Django's regular user model, but 0:47 in an abstract form, or a whole new user. 0:50 Django's recommendation, though, is to just replace the user model, wholly. 0:54 In this case, you extend abstract base user, 0:58 and specify all of your fields, including a unique identifier. 1:00 This model comes with the usual password hashing and security functions. 1:03 I typically only use the first or last methods, 1:07 either creating a new model that's related to a user, or creating a new user. 1:09 Sometimes I even do both. 1:13 Each of these methods have their own strengths and weaknesses, and 1:15 I've linked the docs in the teacher's notes, so 1:17 you can read more about them to make your own decisions about which to use. 1:19 For this course though I think I should use a completely custom user model. 1:23 I want to store an avatar, a display name, and 1:27 I want them to sign up and log in with just their e-mail address. 1:29 Once I do this I'll have to configure Django to use this new user model too so 1:32 that everything will tie together nicely. 1:36 I'll meet you in work spaces in the next video to get started. 1:38
You need to sign up for Treehouse in order to download course files.Sign up