Django — Step 8
Admin Panel Setup
We are continuing off from step 7
In order to login to Django’s admin panel, we need to create super user credentials.
From the terminal run the createsuperuser command:
python manage.py createsuperuser
You will be prompted to enter a name, password, and email. You will use this info to login into the admin panel.
Now start the development server:
python manage.py runserver
Then go to the http://127.0.0.1:8000/admin in your browser and you will see the admin panel login form.
Use the Name and password you just created to login.
All that is available in the admin panel by default is Groups and Users:
If you click on the Users option you will see the superuser we created and are logged in as.
The admin panel is where we can manipulate the data that is uploaded to the database. In order to access the database model we created in step 7 we need to add some code to the admin.py file in the display_1 directory.
At the top of admin.py, we need to import the item model from models.py.
Then we add the registration line, admin.site.register(item):
from django.contrib import admin
from .models import itemadmin.site.register(item)
Save models.py, then log back into the admin panel, or refresh your browser if you are still logged in, and you will see the item section.
Clicking on the item section will take you to a page where you are able to create a new item. Click the add item button on the right side of the page. You will be presented with a form with fields that match the model we created in step 7.
Fill out the title, description1, description2, and select a photo for the photo main field. Save the item and you will be redirected to the item admin page and you will see the item you just created listed.
Go ahead and create 2 more items. We will use these in order to set up the front end presentation of these items in a future step.
Clicking on an item you are given the option to delete it while also being able to update its content.
Keep in mind that by default the name of the items would not be what you would see in the admin panel, but because we added the nested definition of __str___(self) in the display_1’s models.py file it does:
Also if you look in your project directory, a new media folder was created:
This is where the main photo was uploaded to when you created the first item. The folder structure is conveniently organized by year, month and day of upload.
In Step 9 of this tutorial, we will go over how to customize the styling of the admin panel in order to create a unique admin panel with project branding.