The Wayback Machine - https://web.archive.org/web/20241001095653/https://www.geeksforgeeks.org/render-model-in-django-admin-interface/
Open In App

Render Model in Django Admin Interface

Last Updated : 11 Sep, 2021
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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. 

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)


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 – 

 



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-and-installation | django-introduction-set-2-creat
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 how to enhance Django-admin Interface. Project struc
3 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 desirable in a production environment for security or pe
3 min read
Django Admin - Disable the 'Add' Action for a Specific Model
Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. It's designed to help developers take applications from concept to completion as swiftly as possible. One of the powerful features of Django is its settings configuration, which allows you to keep various parameters and configurations in a cen
3 min read
Django Admin - Redesign and Customization
Often the default Django admin page is great and it is all we need for our projects but sometimes we may want to expand what default admin interface can do. We have a lot of tools in Django to customize it to our own needs and in this article, we'll learn how to customize the admin interface and add multiple features: Let's setup your project, add
4 min read
Securing Django Admin login with OTP (2 Factor Authentication)
Multi factor authentication is one of the most basic principle when adding security for our applications. In this tutorial, we will be adding multi factor authentication using OTP Method. This article is in continuation of Blog CMS Project in Django. Check this out here – Building Blog CMS (Content Management System) with Django Setup 2 Factor Auth
2 min read
How to Show a Many-to-Many Field with "list_display" in Django Admin
In Django, the list_display attribute in the Django Admin interface allows developers to specify which fields to display in the list view of the admin panel. This feature is particularly useful for providing a quick overview of the model instances. However, displaying many-to-many fields in the list_display can be a bit tricky since these fields ca
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 of overriding the CSS in Django's admin panel by
3 min read
Making a Django Admin Field Non-Required Without Custom Form Creation
The Django admin interface is a great tool for managing data in your Django application. Sometimes, you may need to make some fields optional in the admin panel, meaning these fields shouldn't be required when creating or updating records. Typically, this is done by creating a custom form. However, there is a simpler way to achieve this directly in
2 min read
How to Override and Extend Basic Django Admin Templates?
The Django admin interface provides a robust way to manage our application's data, offering a user-friendly and efficient design. By default, it gives a clean and functional design that is suitable for most needs. Sometimes we need more customized features to better align with our specific requirements like user-centric experience, custom branding,
10 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 your Django admin account. Reset Password via Djan
2 min read
Render a HTML Template as Response - Django Views
A view function, or view for short, is simply a Python function that takes a Web request and returns a Web response. This article revolves around how to render an HTML page from Django using views. Django has always been known for its app structure and ability to manage applications easily. Let's dive in to see how to render a template file through
3 min read
Render HTML Forms (GET & POST) in Django
Django is often called "Batteries Included Framework" because it has a default setting for everything and has features that can help anyone develop a website rapidly. Talking about forms, In HTML, a form is a collection of elements inside <form>...</form> that allow a visitor to do things like entering text, select options, manipulate o
5 min read
{{ form.as_p }} - Render Django Forms as paragraph
Django forms are an advanced set of HTML forms that can be created using python and support all features of HTML forms in a pythonic way. Rendering Django Forms in the template may seem messy at times but with proper knowledge of Django Forms and attributes of fields, one can easily create excellent Form with all powerful features. In this article,
2 min read
{{ form.as_table }} - Render Django Forms as table
Django forms are an advanced set of HTML forms that can be created using python and support all features of HTML forms in a pythonic way. Rendering Django Forms in the template may seem messy at times but with proper knowledge of Django Forms and attributes of fields, one can easily create excellent Form with all powerful features. In this article,
2 min read
{{ form.as_ul }} - Render Django Forms as list
Django forms are an advanced set of HTML forms that can be created using python and support all features of HTML forms in a pythonic way. Rendering Django Forms in the template may seem messy at times but with proper knowledge of Django Forms and attributes of fields, one can easily create excellent Form with all powerful features. In this article,
2 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 render Django form fields. {{ form.as_table }} will r
5 min read
Understanding Django: Model() vs Model.objects.create()
In Django, when working with models, understanding the differences between Model() and Model.objects.create() is crucial for effective database operations. Both methods serve distinct purposes and are used in different contexts within Django's ORM (Object-Relational Mapping). The Basics: Django ModelsIn Django, a model is a Python class that subcla
3 min read
How to Integrate Flask-Admin and Flask-Login
In order to merge the admin and login pages, we can utilize a short form or any other login method that only requires the username and password. This is known as integrating the admin page and Flask login since it simply redirects users to the admin page when they log in. Let's is how to implement this in this article. Integrate Flask Admin and Fla
8 min read
Adding Tags Using Django-Taggit in Django Project
Django-Taggit is a Django application which is used to add tags to blogs, articles etc. It makes very easy for us to make adding the tags functionality to our django project.Setting up Django Project Installing django-taggit pip install django-taggitADD it to Main Project's settings.py file C/C++ Code INSTALLED_APPS = [ 'django.contrib.admin', 'dja
2 min read
How to customize Django forms using Django Widget Tweaks ?
Django forms are a great feature to create usable forms with just few lines of code. But Django doesn't easily let us edit the form for good designs. Here, we will see one of the ways to customize Django forms, So they will look according to our wish on our HTML page. Basically we will check the methods to include our own custom css, classes, or id
3 min read
Styling Django Forms with django-crispy-forms
Django by default doesn't provide any Django form styling method due to which it takes a lot of effort and precious time to beautifully style a form. django-crispy-forms solves this problem for us. It will let you control the rendering behavior of your Django forms in a very elegant and DRY way. Modules required:django : django installdjango-crispy
1 min read
Integrating Django with Reactjs using Django REST Framework
In this article, we will learn the process of communicating between the Django Backend and React js frontend using the Django REST Framework. For the sake of a better understanding of the concept, we will be building a Simple Task Manager and go through the primary concepts for this type of integration between React js and Django. Reactjs in a nuts
15+ min read
How to Fix Django "ImportError: Cannot Import Name 'six' from 'django.utils'"?
After Django 3.0, django.utils.six was removed. The "ImportError: Cannot Import Name 'six' from 'django.utils'" error occurs because of the dependency issue. This happens because when the project tries to use something that’s no longer available. Don’t worry—it’s easy to fix. We’ll explain why this error happens and give you simple steps to solve i
3 min read
Django App Model - Python manage.py makemigrations command
According to documentation, Migrations are Django’s way of propagating changes you make to your models (adding a field, deleting a model, etc.) into your database schema. They’re designed to be mostly automatic, but you’ll need to know when to make migrations, when to run them, and the common problems you might run into. makemigrations are run thro
2 min read
Django model data types and fields list
The most important part of a model and the only required part of a model is the list of database fields it defines. Fields are specified by class attributes. Be careful not to choose field names that conflict with the models API like clean, save, or delete. Example: from django.db import models class Musician(models.Model): first_name = models.Char
4 min read
Creating custom user model API extending AbstractUser in Django
Every new Django project should use a custom user model. The official Django documentation says it is “highly recommended” but I’ll go a step further and say without hesitation: You are straight up crazy not to use a custom user model up front. Why do u need a custom user model in Django? When you start your project with a custom user model, stop t
4 min read
How to use User model in Django?
The Django’s built-in authentication system is great. For the most part we can use it out-of-the-box, saving a lot of development and testing effort. It fits most of the use cases and is very safe. But sometimes we need to do some fine adjustment so to fit our Web application. Commonly we want to store a few more data related to our User but the ne
3 min read
Model Fieldname restrictions in Django Framework
A Django model is the built-in feature that Django uses to create tables, their fields, and various constraints. In short, Django Models is the SQL of Database one uses with Django. SQL (Structured Query Language) is complex and involves a lot of different queries for creating, deleting, updating or any other stuff related to database. Django model
2 min read
How to create Abstract Model Class in Django?
Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source. What is model Inheritance? Model Inheritance in Dja
2 min read
Practice Tags :