Using the Django Admin Interface
In this video, you’re going to learn about the Django admin interface and how you can use it to conveniently interact with your database. Django comes with a few things built in from the get-go. In your
settings.py file, there were apps that came pre-installed. One of them is the
So as you know, Django comes built-in with a couple of things from the get-go. We’ve seen that—inside of our settings file—we saw that there’s a lot of apps that come already installed. One of them is the
admin app, and we haven’t seen this one yet, but we’ve encountered it before.
Let’s give this a try. If instead of
/projects I type
/admin, let’s see where we go to. See? There’s like a whole nicely-styled page that’s just sitting there, that is part of our project that we didn’t even know about.
01:41 So when I run this, it asks me for a username—I’m going to put in my name here. Email address—I’m just going to leave that blank. And then pass in the password—“Pass in the password.” All right. Repeat.
02:20 I’m putting in my credentials. Let’s see if I can type my password correctly this time. It looks good. Okay. So, I’ve entered the Django administration in here and we can see, like, it looks like we’re probably able to do some things here: Add, Change, Users—what do we have in here? Let’s take a look. Interesting, so this is the user that I just created, and then there’s another superuser that I created earlier on.
02:49 So, there’s currently two users. And this looks very much like a table. So, what we’re interested in, actually, is not the groups and users, though. We’re interested in the projects, so that we would be able to add projects, edit projects, and delete projects from a convenient admin interface in here.
Django makes that actually very easy. Some things we need to do, and the first thing is we need to register our models in the admin interface. For that, we’re going to open up a file that we haven’t looked at yet inside of our project. That’s
admin.site.register and then pass in the name of my model that I just imported. And that’s really all. It’s just these two lines of code, and this already allows me to have access to my models inside of the Django interface. Let’s take a look.
We need an image. Some suggestions of some that I did before,
project/img/daily.png. We have this one inside of our
static/ files already—there it is—which means I’ll be able to link to it. I SAVE this.
Let’s take a look. It correctly renders! And here it is with a new image. Can I also click in here? I can! Great. And as you can see, because we’re using the
id, or the primary key, this is also number
5, up here. Number
3, and number
4 were created, but then deleted, but the database didn’t update the IDs.
06:41 Yes, I’m sure, let’s get rid of it. Heading over to our app again, there it is! It’s gone. So as you can see, this Django administration is an awesome tool for interacting and updating your app, and this already comes built-in with Django.
So, the only thing you need to do is create your project and make sure that the
admin app is installed, register your models. And then you’re able to very, very conveniently interact with your database, add projects, remove projects, or edit projects—the text in there, the image, the technology, whatever you want.
07:16 So, that’s a great way of keeping your site easily up-to-date. With this, we’re at the end of this course. So, in the next video, we’re going to do a quick recap of what we learned in this section, and then I have a couple of suggestions for you in how you can still improve this project to make it even more awesome than it already is.
Become a Member to join the conversation.