how to use list_display in django

Published: 22 June 2017
on channel: Open Source Devops
2,962
26

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...


Watch video how to use list_display in django online without registration, duration hours minute second in high quality. This video was added by user Open Source Devops 22 June 2017, don't forget to share it with your friends and acquaintances, it has been viewed on our site 2,962 once and liked it 26 people.