Adding User Profile Django 1.11

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
when it comes to creating users profile in Jungle you can find yourself stuck in many options each of them has its own advantages and pitfalls the first way is by extending the existing user model so we start by creating a model that inherits from abstract user class since this class provides the full implementation of the default user model and then you add kids as you would normally do with any model it's ideally to do this process at the beginning of your project and it will completely change your database schema so when I first start the migration you use a model has completely changed and the difference we created and now in the existing user model the second way is by creating a new model and adding one to one relationship between the user model and the profile model so each user can have a profile and each profile belongs only to one user by the end when you run the migration a new table will be added to the database for me I prefer the second way since it offers much more simplicity by avoiding touching the base model so if you argue with my personal opinion continue watching the rest of the video so you can see it in action alright it looks like we have the same opinion so let's begin the first thing as I said before is you create a new model so let's open models of pure file by going to project Explorer and the accounts folder I'm using Python IDE so control shape and and then models of py we create a new class user profile model that in hit four models both model so other expert a second ago pro/5 belongs to one user so user equal models one-to-one field and then takes our the first parameter the model that we want to have a relationship with let's import the user model at the mental and let's add cannot delete so whenever the user deleted account you want reserved we profile the second field is gender of type character field so jungle equal model dot champion now let's set marks against one we limit the choice between male and female so choices equal we define the values inside tuple so M stands for meg and L stands for female and let's set blank to through the search field is age which is a positive integer so H equal models both positive integer we set blank true and not the true to not force the user to enter his page next to override the STR method and we return the user username finally let's add the metaclass so we define verbs name equal to profile and then a laurel equal to profile let's generate the migration let's open terminal and python monolith py make migration let's give it a name add user profile let's check if the migration has been created in the migrations folder once that's done we apply the migration Python manage the py migrate let's on ourselves first Python - dot dy our server open your browser and navigate to admin area let's type a username and password now if you take a look here you only see a Fanta Gatien and authorization application that comes by default if jungle let's jump back to our IDE and there is the our model to the admin area let's go can admins of py file now let's create a class user profile admin and we in head from admin dot model Ali let's add leaf display here and let this table save user gender and age next register the model sole admin dot sight but register user profile admin admin enter to import the model and user profile admin let's come back to our browser take rush let's enter the profile model and it's empty for anything now let me tell you the scenario whenever you use the register himself we want to find an empty profile to him and if you remember from previous video we created a register view so let's jump back to our views of p1 5 in the register user view let's add it provide the new user so after saving the user we call the user profile model I'll turn enter to import the model dot objects top create and you assign the user to the new user let's register a new user and see now let's jump back to the admin area and the profiles model sleep the profile has been created you can extend this to whatever you want for example you can add image create phone number you can add the poem so the user can edit is profile thanks for watching if you have any question let me know in the comment box
Info
Channel: Human Code
Views: 6,324
Rating: 4.9619045 out of 5
Keywords: Django profile, Django user profile, create django user profile, Django 1.11, Add user profile Django, Python User Profile
Id: r1WlFFJOSFo
Channel Id: undefined
Length: 7min 30sec (450 seconds)
Published: Tue Aug 15 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.