Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Django
  • Views
  • Model
  • Template
  • Forms
  • Jinja
  • Python SQLite
  • Flask
  • Json
  • Postman
  • Interview Ques
  • MongoDB
  • Python MongoDB
  • Python Database
  • ReactJS
  • Vue.js
Open In App
Next Article:
How to Override CSS in Django Admin?
Next article icon

Render Model in Django Admin Interface

Last Updated : 11 Sep, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

Rendering model in admin refers to adding the model to the admin interface so that data can be manipulated easily using admin interface. Django’s ORM provides a predefined admin interface that can be used to manipulate data by performing operations such as INSERT, SEARCH, SELECT, CREATE, etc. as in a normal database. To start entering data in your model and using admin interface, one needs to specify or render model in admin.py.

Render Model in Django Admin Interface Explanation

Consider a project named geeksforgeeks having an app named geeks. Let us initialize a model having fields title, content, views, URL, image, etc as in a blog. To know more about various fields and their implementations visit Django model data types and fields list. 

Refer to the following articles to check how to create a project and an app in Django. 

  • How to Create a Basic Project using MVT in Django?
  • How to Create an App in Django ?

Enter the following code into models.py file of geeks app.  

Python3




from django.db import models
from django.db.models import Model
# Create your models here.
 
class GeeksModel(models.Model):
    title = models.CharField(max_length = 200)
    content = models.TextField(max_length = 200, null = True, blank = True)
    views = models.IntegerField()
    url = models.URLField(max_length = 200)
    image = models.ImageField()
 
 

One can easily create instances of this model using django shell but to access the admin panel and use admin panel for inserting, deleting or modifying the data following steps are to be followed: 

  • Before starting to use admin interface of django one needs to create superuser in django. A superuser is like an admin who can access and modify everything of a particular Django project. To create a superuser enter the following command into the terminal.
Python  createsuperuser
  • Enter your Name, Email, Password, and confirm password. 

render-model-in-admin

  • Now let us login into the admin panel 

log-in-django-admin-models

  • Its time to render our model in this admin interface. Go to admin.py in geeks app and enter following code. Import the corresponding model from models.py and register it to the admin interface. 

Python3




from django.contrib import admin
 
# Register your models here.
from .models import GeeksModel
 
admin.site.register(GeeksModel)
 
 
  • Now lets check our admin interface. visit http://localhost:8000/admin/ 

render-django-admin-interface-models

  • To add data into the model, tap add and enter corresponding data into the required fields. click on save. 

render-admin-django-models

Bingo..!! Model GeeksModel has been successfully rendered into the admin interface. One can similarly render all types of models and any number of models in the Django Admin Interface. 

Also Check – 

  • Change Object Display Name using __str__ function – Django Models
  • Built-in Field Validations – Django Models

 



Next Article
How to Override CSS in Django Admin?

N

NaveenArora
Improve
Article Tags :
  • Python
  • Django-models
  • Python Django
Practice Tags :
  • python

Similar Reads

  • Python | Django Admin Interface
    In this article, we delve into the capabilities and advantages of the Django Admin Interface, exploring how its customizable features and streamlined workflows empower developers to effortlessly administer their projects, from data management to user interactions. Prerequisites: django-introduction-
    4 min read
  • Customize Django Admin Interface
    Django admin by default is highly responsive GUI, which offers various features and an overall CRUD application to help developers and users. Moreover, Django admin can be customized to fulfill one's needs such as showing fields on the home page of the table, etc. In this article, we will discuss ho
    3 min read
  • How to Override CSS in Django Admin?
    Django's admin interface is a powerful tool for managing application data. It comes with a default styling that may not always fit the visual identity of your project. Customizing the admin interface can help create a more cohesive user experience. In this article, we'll walk you through the process
    3 min read
  • Built in & Custom Model Managers in Django
    Django manager is a class that acts as an interface through which Django models interact with databases. Every model has at least one manager object. It has a lot of methods, attributes to ease working with databases. In fact, many beginner-level Django developers do not know that they use the Manag
    6 min read
  • How to Render Data in Django
    Django's render() function is a fundamental tool for building dynamic web applications. It simplifies the process of combining HTTP requests with HTML templates and dynamic data, making it easier for developers to create interactive and data-driven web pages.  What is render()?In Django, the render(
    3 min read
  • How to Reset Django Admin Password?
    Forgetting or needing to reset the admin password in Django is a common issue that can be resolved in a few easy steps. Django provides several ways to reset the admin password, depending on the situation. In this article, we'll explore multiple methods to help you recover or reset the password for
    2 min read
  • Disable Admin-Style Browsable Interface of Django REST Framework
    Django REST Framework (DRF) is a powerful and flexible toolkit for building Web APIs in Django. One of its features is the browsable API, which provides a user-friendly, web-based interface for interacting with the API. While this can be helpful during development and debugging, it may not be desira
    3 min read
  • Add a Placeholder on a CharField in Django
    Django is a popular web framework with Python that builds scalable and robust web applications. One of the common tasks in web development is creating forms for user input. To improve the user experience, you may want to add placeholders to form fields, which are helpful hints displayed inside the i
    5 min read
  • Render Django Form Fields Manually
    Django form fields have several built-in methods to ease the work of the developer but sometimes one needs to implement things manually for customizing User Interface(UI). We have already covered on How to create and use a form in Django?. A form comes with 3 in-built methods that can be used to ren
    5 min read
  • How to Extend User Model in Django
    Django’s built-in User model is useful, but it may not always meet your requirements. Fortunately, Django provides a way to extend the User model to add additional fields and methods. In this article, we'll walk through the process of extending the User model by creating a small web project that dis
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences