Admin and Apps - Django Web Development with Python p.3
Skills:
API Design80%
Key Takeaways
Configures admin functionality and apps in Django using Python for web development and application management
Full Transcript
what's going on everybody Welcome to a part three of the D Jango web development series I'm your host sentex and let's get into it today what we're going to be talking about is the admin page of Jango as well as a an opportunity for me to show off just how easily we could incorporate other people's apps for all kinds of things and we'll just show a really quick example by the end of this one so let's get into it so the first thing we're going to do is to use admin we need a super user we don't have one uh so the first thing that we're going to do is uh create one so I'm going to open up command prompt here and I'm going to say python manage.py create super user and then here what we're going to do is pick um a username the default would be like your computer's name I'm using a paperspace uh virtual machine here so that's why it says paperspace but I'm going to call mine sentex email address you can put one or not it doesn't really matter if you do have one later on down the line like right now we're running Jango with debug equals true so we get and see the debugging messages so it's no big deal later when you push your website to production D Jango has a sort of reporting functionality because you won't be running with debug equals true and you can incorporate um and allow D Jango to actually email you when certain errors are hit so there could be a reason you want to add an email address here but just like everything else with Django if you decide not to do it now like that you can always come back and revisit this later you can just edit the username and add the email address no big deal password I always use programming as my password duh or python is amazing one two3 Okay so we've got a uh user created and we're ready to rumble side note of course don't make your password super simple for your admin account uh otherwise someone could log into your admin and then what I'm about to show you with admin should tell you why you wouldn't like that to occur okay so uh what we want to do now that we've got this admin user we actually could run the server and uh check things out so actually I'm going to go python manage.py run server because I don't have another one running right now and let's go ahead and head to our website SL admin boom we get a log in and it's way zoomed in okay uh sentex and programming is awesome one two three okay uh and what we get here is the D Jango admin page here we can see uh a couple of things we've got groups and users we could go ahead and click on users boom there's your sentex user that you just created we could click on that user boom we've got the username password which is this uh hashed out password basically um but then here we've got some personal information that we could change uh the reason why this is all here is because the admin user or the super user is is just a version of a user and the user the D Jango user model uh has fields for name and email address and all that so anyways that's why that's already there now I know you must be wondering well what about our model cuz we just made a model in the last tutorial where's that at well you have to register your models so uh you go to the Django registration you cut out the little piece of the cardboard that your Django package came in any I cracked myself up okay so what we got to do is uh go into Main and we just go into the admin here and in fact I told myself I was going to keep using this one so we go here and register your models here so all we have to do is actually import the tutorial model so from Models import tutorial don't forget the relative period there uh and then all we need to do is admin. site. regist register and uh we can do tutorial like that tutorial hopefully I spelled that right let's find out let's refresh boom tutorials interestingly enough this has an S appended to it uh even though the you know tutorial is singular uh I forget what it is it's there there is a a method you can override eventually we will probably hit it um but uh cuz it's kind of annoying so a term like series what it's going to do is just adds an S to it it doesn't have any handling for if the thing ends an S maybe do like e or or just an apostrophe or something doesn't it's really stupid it just adds an S so so anyway later we could fix that but that's where the S is coming from it's literally taking the model name plus s so um yeah but later on down the line when you're like trying to go back and figure out where is it getting the name from that's what's going on so anyway been there done that okay so that's how we could register it super simple and if we click on tutorials boom we we can already see the tutorial that we actually made and all the fields are here and notice how like you the date published has this thing like today and now and you could click on a calendar and pick all these things are done for us and like for example here this is car field and it's just like a short field and here you got this big field here because it's a text field and um I just think that's so cool if anybody's ever had to make an admin like control panel and ACP uh and needed to do all of this stuff uh that's a lot of work and even though this is like super basic I mean a lot of stuff went into this and that's pretty awesome so Okay so we've got that done now uh the next thing I want to talk about is how we can kind of customize this slightly later on it's it it could get even more more crazy uh than what we're about to do but just to show you that you can do this uh what we'll do is rather than just registering the model so for example your models could have like 100 attributes but you might only want to edit a handful of them like some of them might be defaults like what was the temperature or or something like that that you would never edit okay um so you might not want all the fields you also might want to like organize the fields in different ways or in different orders and so on so or set for example a default so right now if I go to the tutorial and either add tutorial here or even back here you could say add so we could add another tutorial here um um let's just add a quick uh print tutorial tutorial actually I'm going to save this for now I I don't want to add one right now I'll save that for later we will add some more uh but I'm going to wait until after the amazing app changes so the first thing that we should do is how can we customize like the order and like the setup of tutorial here so what we're going to do is uh we could say here class and we're just going to say tutorial admin and this uh it will inherit from admin. modeladmin so it's just it basically um when we register all we're going to do is actually register tutorial with tut tutorial admin here and this was just assumed before now we're just overwriting it basically and these are the parameters by which we are going to overwrite it we're going to say hey we want the following fields and you'll just pass a list here so for example each field would be an attribute so tutorial title was one of them um and let's just add the because it was three then we had tutorial content and then we had tutorial published uh should be right let's refresh real quick make sure it's all looking hunky dory sure enough okay but tutorial published maybe we want that like up above right so what we could do is come into here and just change the order cut paste that was ugly oh this is so ugly o almost got got by that not today python not today okay so now we got the different order here um another thing that we could do is you can separate them by Fields uh just again if you had like a 100 you might want to like uh cluster them together or something so this we don't really have enough to to show that truly um but but anyway uh I'll just show it real basically uh okay field sets Okay so now we can actually separate them into sets so for example we could say title date in this set [Music] is fields and then in here we'll put uh tutorial title and tutorial published then we'll have another set which will be called content and then in here we can pass fields and then tutorial content then I can get rid of that uh hopefully hopefully we didn't error let's see what happens boom awesome wow usually I would make a typo by then so as you can see we got these like little dividers basically uh for the DAT data types okay pretty cool pretty cool um the next thing is that we could do is for example if I go to uh I don't want to delete let's go to tutorials add a tutorial you can see here like the date is empty one of the things that I wouldn't mind doing really quickly is uh changing our model here let's go models.py and here you see where we have tutorial published equals model. dat time field and we call it date published uh one of the parameters that we can put into one of these is a default so I would like the default to be uh date time now so what we can say is from date time import date time and then date time. now boom save that and that would be a change to our model so I don't think we're going to get away with uh let's see what happens I'm trying to decide if that would require I don't imagine that's going to require a migration I don't know that's a good question actually let's see what happens nope didn't require a migration nice so now when you hit new tutorial boom that's already in there so why that didn't require migration I guess you would have to it must be D Jango is running like python to set those defaults would be my guess because this is never it's not an SQL default right it's because this be as we when we hit new right here this doesn't create any SQL yet nothing is you know inserted SQL wise until we probably hit save so that's probably why we didn't need to migrate but we also could have found out like if you're if you're uncertain you're it's never going to be a big deal if you uh if you get lost how many things do I going to minimize if you just quickly do a uh python manage.py make migrations if you just check um wow it actually alter so it does want to alter it fascinating but it actually made the change interesting already forgot uh let's just I guess we could go ahead and python manp migrate fine okay hey that's interesting even though that was already hand it didn't seem like a migrate was required anyway okay very very interesting so the big thing now um is when I come into here like imagine actually trying to write tutorials in here now maybe not everybody here has written a tutorial but uh this is like plain text which would be really really painful and very tedious also you guys probably don't want to read python code written St straight into there that would probably not be uh Pleasant so instead what we'd want is some sort of like editor and they make editors called like what you see is what you get types of editors now I just did a quick search for some editors for Django and I found that there's one called tiny mce4 dasl so all we need to do uh to grab that and that's like that's ajango app that we can just add to our app so all we need to do first is install it so I'm going to come over I'm guessing this is nope wrong okay so I'm going to come over here and real quick um I already forget if pip corresponds to 37 or not yes so I'm going to go pip install D Jango Das tiny mce4 dash light uh what oh it was Slash pip somehow okay I like I just checked pip okay okay so um if you want to follow along you can it's pretty lightweight package if you don't want to follow along and just watch that's totally fine too um but basically my goal here is to just show you how quickly and easily you can add someone else's app so anyways pip install D Jango uh this is basically it's just something that's going to override certain um model types so what we're going to override here is the like this text field that we've got and we're going to turn that instead into like an editor So Okay so we've installed D Jango tiny mce4 light great so we have that now what we need to do is add this to our installed apps because we want to call upon it we want to be able to point URLs towards it and so on so uh first thing we're going to do is stop trying to edit in here go to our little Sublime here and we're going to go into my site and settings. P come down to installed apps and I'm just going to add it down here and I'm going to say tiny MCE is the name of the app so the next thing I'm going to do and by the way if you are curious about it um I do have I put a link to the textbase version in the description and you're definitely going to want to start heading that way really quickly because I'm going to make this huge copy and paste that there's no way I'm going to write out on a video boom there's the copy and paste so these are the configuration settings for our uh tiny MCE widget uh basically it's all the things that we want included here what are the things that I want to like be able to click on and buttons and all that kind of stuff so anyways that's there um cool so there's that and in the so if you go to the text Bas version of the tutorial you can just copy and paste that snippet also I link to all of the config possible configurations so if you wanted to kind of change this around this is just one of the the more defaulty uh ones the next thing we will need to do is be able to point our app to Tiny MCE because our widgets are going to call upon tiny MCE to work so we're going to come down here and we're going to say path and we're going to allow the path of tiny MCE and basically that's going to uh work with include tiny mc. URLs this needs to be in quotes cool add the comma so I don't forget later on all right so now what we want to do is hopefully save that let me make sure we're not hitting errors yet good looks like everything's working up to this point now what we want to do is head over to our admins so in main admin.py now what we want to do is uh first we need to make the import uh and what we want to say is from Tiny mc. widgets we're going to import import the tiny MCE widget also uh from django.db we're going to import models cuz we're actually going to just modify the model here for admin purposes so we wouldn't want we don't necessarily want every text field to be an editor right across our entire website we just want the this one we just want one to be so what we're going to say here is basically under our field sets we're also going to make a quick change and we're going to say uh form fieldcore overrides equals and then uh we're going to say models. text field that's actually title case text field uh and that will be a widget widget and that's tiny MCE oh my goodness there we go okay so that will override that uh that specific text field just for tutorial admin for us we could do the something very similar in our models and all that kind of stuff there's there's other ways and like so for our views uh to display uh to like a regular user like right here we're making all these changes to admin.py which is kind of like its own separate entity although some people have I've seen people use admin and they like extend the admin to actually be their main website it's kind of not suggested that you do that but you you I suppose you could but I'm just letting you know this is not the only use case for tiny MCE or any app for that matter or any widget that you want to grab that happens to be an app and so on anyway save that come over here let's make a refresh darn it can't get through a tutorial without something like that um [Music] H let's see what did I do wrong this probably needs this needs to be uh I wonder did I get sometimes that autocorrect smacks me in the face or not like auto correct but the suggestion I pretty confident I didn't make that mistake thanks anyway like sometimes it suggests then I hit enter to like make a new line or whatever and yeah yeah all right anyway long story short boom we have an editor now awesome great wonderful okay now so like for example we could say like print tutorial okay and then we come down here and uh you know you could write stuff here here's how to print things things and then like you can even enter like a code snippet so we'll just do this and we'll Define print stuff uh and then we can pick a language we'll go with python print and then we'll underscore here CU that's proper the thing and print the thing thing um also we'll return the thing because why wouldn't we print stuff who awesome so then we've entered a little snippet boom save that boom now we got two tutorials holy [Music] moly okay anyway um all right so we've got these tutorials and now we want to be able to display them and stuff and we definitely don't want our homepage looking like that anymore so now we're going to start moving into is like views and templates and stuff like that and getting our website to uh look a little better and then we'll get very briefly I promise into some design and then back to other Django stuff so uh that's it for now quick shout out to my most recent channel members we've got KB Jag dish isan AJ Kumar and Robo 11735 thank you guys very much for your support you guys are awesome that's it for now questions comments concerns whatever feel free to leave them below otherwise I will see you guys in another video
Original Description
Welcome to part 3 of the web development with Django and Python tutorial series. In this tutorial, we're goign to be checking out the admin functionality that comes with Django.
Text-based tutorial: https://pythonprogramming.net/admin-apps-django-tutorial/
Channel membership: https://www.youtube.com/channel/UCfzlCWGWYyIQ0aLC5w48gBQ/join
Discord: https://discord.gg/sentdex
Support the content: https://pythonprogramming.net/support-donate/
Twitter: https://twitter.com/sentdex
Facebook: https://www.facebook.com/pythonprogramming.net/
Twitch: https://www.twitch.tv/sentdex
G+: https://plus.google.com/+sentdex
#django #web-development #python
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from sentdex · sentdex · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
Python Encryption Tutorial with PyCrypto
sentdex
Python's Logging Function
sentdex
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
wxPython Programming Tutorial 4: Panels
sentdex
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
wxPython Programming Tutorial 8: Custom Button Images
sentdex
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
Basic PHP Tutorial 12: Associative Array
sentdex
Basic PHP Tutorial 14: Foreach loop
sentdex
Basic PHP Tutorial 16: Include and Require
sentdex
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
Basic PHP Tutorial 4: Variables and Comments
sentdex
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
Basic PHP Tutorial 1: Intro to PHP
sentdex
Basic PHP Tutorial 3: HTML with PHP
sentdex
Basic PHP Tutorial 9: While Loop
sentdex
Basic PHP Tutorial 10: Switch Statement
sentdex
Basic PHP Tutorial 2: Print and Echo
sentdex
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
Basic PHP Tutorial 19: Finding words in strings
sentdex
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
Basic PHP Programming Tutorial 24: String similarity
sentdex
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
Sikuli Tutorial 1: Visually programming in python!
sentdex
Sikuli Tutorial 2: Program visually in python!
sentdex
Sikuli Tutorial 3: Program visually in python!
sentdex
3D Bar Charts in Python and Matplotlib
sentdex
3D Plane wire frame Graph Chart in Python
sentdex
Raspberry Pi Part 1 Introduction
sentdex
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
Raspberry Pi Part 11: Remote Desktop
sentdex
Twitter Analysis: How to rank a user's influence
sentdex
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex
More on: API Design
View skill →Related Reads
📰
📰
📰
📰
Corvorum OS 1.0 - Sistema Operativo Tecnomántico
Dev.to · Technomantus Corvi
Why Materials Scientists Are Still Copy-Pasting Data from PDFs in 2026 (And Why AI Changes…
Medium · AI
How to Actually Cap AI Spend for Your Users: 3 Edge Cases Everyone Misses
Dev.to · CJ Cummings
Nano Banana 2 Lite with Kiro
Dev.to · xbill
🎓
Tutor Explanation
DeepCamp AI