In this Django tutorial, we are going to learn how to customize the admin interface. Django ships with many of options to improve the Django admin interface. We will take a look at many of them in this tutorial. Let's get started.
How To Customize The Admin Interface In Django
When making changes to the admin interface it's highly recommended that we add a class to our admin file that in encapsolates our options code. We add the class above registering our model and call this class AppnameAdmin so in our case our new class will be called LessonAdmin.
Let's create our class. Create a class in your admin.py file call it LessonAdmin and place it above our lesson admin registration. This class is a subclass that inherits from ModelAdmin class. So, we need to add admin.ModelAdmin to inhertate from the ModelAdmin class.
code Example:
models.py
from django.db import models
Create your models here.
class Product(models.Model):
product_name=models.CharField('NAME',max_length=25,default="")
price=models.IntegerField('PRICE')
qty=models.IntegerField('QTY')
exp=models.DateField('EXP')
def __str__(self):
return self.product_name
admin.py
from django.contrib import admin
from . models import Product
Register your models here.
class Productadmin(admin.ModelAdmin):
list_display = ('product_name', 'price')
list_filter = ('exp','qty')
admin.site.register(Product,Productadmin)
~-~~-~~~-~~-~
Please watch: "create data dictionary using code"
• create data dictionary using code
~-~~-~~~-~~-~ buy a coffee for me on this URL https://opensourcedevops.web.app or PayPal donation https://www.paypal.com/paypalme/OpenS...
Смотрите видео how to use list_display in django онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Open Source Devops 22 Июнь 2017, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 2,962 раз и оно понравилось 26 людям.