Render Model in Django Admin
After creating the model we need to add data from to our model. We can add data in two ways. These are –
- Django Shell
- Django Admin
In this article, we will focus on rendering model data through Admin Interface. If you want to learn about rendering data through Django Shell refer to Django ORM – Inserting, Updating & Deleting Data.
We need to create a superuser for our web application that will access the admin panel. To create a superuser type the below command in the terminal –
python manage.py createsuperuser
Now go to http://127.0.0.1:8000/admin on the browser to access the admin interface panel.
Give the username and password created for the superuser and then the admin dashboard will open.
To render our model onto our admin panel we need to make changes to the post/admin.py file. Enter the following code to the admin.py file –
Python3
from django.contrib import admin from .models import Post # Register your models here. admin.site.register(Post) |
Refreshing your admin panel will let you see the model that we created.
Note: For more information refer to Render Model in Django Admin Interface.
Let’s add some data to our database. Clicking on the Geeks Model we will see something like this –
We can click on the Add Post button on the right top corner and then we will be able to see the fields for adding data. See the below image –
After adding the required data we will see something like this on our admin dashboard –
Getting started with Django
Python Django is a web framework that is used to create web applications very efficiently and quickly. Django is called a battery included framework because it contains a lot of in-built features such as Django Admin Interface, default database – SQLite3, etc. Django provides various ready-made components such as a way to handle user authentication, a management panel for your website, forms, a way to upload files, etc.
In this article, we will learn Django by creating a basic blogging web application.