Creating form for user profile model in django

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello everyone i am ash patel and welcome to my channel jango world so in last video we have created this user profile model right so we need to add more two more fields so i forgot actually so we will add it now so here i will say education equals to models dot text field okay and here it is going to be blank equals to true and we have one more which will be work work okay now we will just migrate the changes so i'll just activate terminal sorry environment okay now here i'll say python run server right so server has been started but we need to migrate so i'll say make migrations python menu dot py make migrations okay then i will just do migrate okay what migrate so we don't have any migrations to apply it okay so after doing that we will just simply run the server okay so i'll say run server oops okay now i'll just copy this link and open in my browser so i'll just log in over here with my username and password and you can see we got this interface so this is bug actually we will fix that okay because we are going to change this whole interface so we will fix this later okay now what i want to do is like we should you know show the user button to edit his or her profile so first i'll just create drop down over here okay so i'll go to get bootstrap.com and in docs we will go to drop down section so here it is drop downs inside the components okay so i'm searching for drop down which will open left side so this is that drop down so i'll just copy this okay and i'll go to vs code now here i am just going to paste that so i'll just open templates authors and uh not authors containers navbar okay so here we are going to see okay this look if loop okay so here we are checking for authenticated user if user is authenticated then we need to show them the drop down so here i will just paste that okay now i need links inside this drop down right so i'll go again on that website and i'll just print this link okay and i'll paste that over here okay so i will just copy this username variable and paste that over here okay now here inside this a link i will you know print users first name and last name so i'll say user dot first underscore name and space user dot last underscore name okay so this should bring you know user's first name and last name so let's that let us see that refresh and yeah we can see that right so i want this menu to be dark because we are using dark theme over here so i'll say drop down hyphen menu hyphen dark so that is bootstrap class okay this is bootstrap class and now i will just add a br tag at the end of this last name variable br i need to turn this to html mode okay now i will add username so i'll say user dot username right now here i should see both so i'll just add right over here okay now once this is done uh i will add a hr tag okay so i'll say li hr and here i will say class and i'll go to bootstrap and i will search for hr tag okay so i need this divider class so i'll just copy that class from here and in vs code i'll just paste that now here once this user clicks over here we need to redirect it to this page right so here i will just copy this link and paste that over here refresh okay we are redirecting right you can see so here i am just going to you know remove this font awesome icon so font.some icon is over here right i'll just copy that and paste that over here okay so now i think everything is good right and i'll copy this divider again paste that and i'll copy one link and bring down and i here i will write log out okay or let's say sign out and i will copy this log out link and paste that over here now i don't want this both link okay and refresh so here if i click on this logout then i should log out right and if i login again oops okay so i should log in and if i click over here i should redirect to this profile page okay so now once this is done uh let's you know do some more thing like we will create a settings page let's get do that afterwards for now let us focus on uh this form which can update the user right so i will close this both file now i will open this authors app now inside this i will just go to forms dot p by okay now in here i will first import you know user's profile so i'll say from django not django sorry from dot models oops models import user profile okay now once this is done i will create one form so i'll say class user public or public details form okay now here i am just going to say forms dot model form okay now here i will say class meta here it will take model equals to user profile so i have missed misspelled this profile spelling okay in our database so keep in mind okay and i will say fields equals to underscore underscore all underscore underscore okay after creating this form i'll just copy this name and i'll go to views.p by and here i will import that form so i'll say from dot forms or we have already imported right so i'll just you know do comma over here and paste the tag name okay after doing that we will go very down and here i will create class for update public details okay and here i will say generic dot update view okay now here it is going to take form class so i'll say form underscore class equals to user public detail form and we are going to pass this login mixing and the success measure message mixing so i'll just copy that and paste over here okay now here i will say login url login underscore url equals to login only and i think it is going to be same as this view only so i'll just copy that anyway we are not going to repeat the code again okay once this is done we will you know edit this template name so we are going to say edit underscore public underscore details dot html and i will copy this file name and i'll go to templates authors and here i will create that file and hit enter after doing this here i need to write dot user profile okay i think we are good to go so first i will copy this class name and go to urls.pi now here i am just going to you know create this url after this delete so i'll just say path and here i will write update update underscore url sorry public underscore details slash since update view takes uh integer i mean foreign key or slog so i'll say int pick k okay and inside here i'll say views dot our class name so i'll say update public detail not form what was it's here so i'll just copy and paste that and i'll say dot as underscore view now i'll say name equals to user underscore public underscore details so once this is done i'll just copy that okay and in containers nav bar now we are going to show that option somewhere here so i will just add this url url and i will paste that and i will say user dot id now once this is done here we are going to say um let me intend before doing that we are going to say update update public details okay so this is done now come to browser refresh and in drop down we'll click over here so we are having error okay so since we misspelled you know this model name we need to copy this model name and write same as over here because you know we wrote profile over here and here we are writing fu so in profile spelling we don't write fu right we don't write you basically so that's why we are getting error after pasting that name make small u and small p just save this come over here and refresh so we have one more error for okay we need to write form class not forms classes okay so our template is empty so here i'll go to template author and in this user i'll just copy this template name hold code actually not template name and inside this edit public details dot html i'll just paste that save this come over here refresh and you can see we got this form okay so here i will say dot s underscore p refresh so we got this inline form now i will open this incognito browser and i will open admin panel with admin credentials so in this users so since we are logged in with uh admin admin okay profile so we have admins profile also if you don't see this admins profile then please create one okay manually because we created super user before creating this user profile so it will not create automatically okay so inside this we should you know see our date of birth right so here i will just write date of birth and i will also upload one image so [Music] let me download from pixels.com okay let us download this image just download free okay so this image is downloaded now i will go to downloads and upload it okay i'll say update user so if i come to hta i'm in my admin panel and refresh over here then you can see i got this birthdate so we are not getting this uh file i mean this is not updating our uh image which we have uploaded so for that we need to go to form and here i will first change the mode of my language to html instead of django html and i will say encrypt type it should be multipart form data okay after doing this you should be able to upgrade upload the image so i'll go to admin profile again okay and i'll go to update public details here i will just upload the image and update user now if i come over here in admin panel or here you can see now we have media folder and inside which we have the image and if we see in our admin panel and refresh over here then you can see we got this image over here also okay so in order to upload files from your forms then you need to write this as it is not going to accept okay so after doing this um we are now going to design this page okay so this is very basic page right so we are going to design this so let me see if this video will be long then we will not able to continue okay so this video has already crossed 22 minutes so this we will we will design this page in next video so yeah this is it for today's video guys if you like my video please like share and subscribe to my channel and i will see you in next one thank you [Music] you
Info
Channel: Django World
Views: 1,126
Rating: undefined out of 5
Keywords: how to create user profile form in django, user profile in django, django user profile, user profile, django tutorials, django tutorial, django tutorial python, django 4.0 tutorials
Id: oa90Yf-gyT4
Channel Id: undefined
Length: 19min 13sec (1153 seconds)
Published: Sun Jul 17 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.