Customizing Django Admin Django.How

Author avatar wrote on 26/05/2022

Open admin.py file in the app folder you want to customize

This will show listings in a standard way


from django.contrib import admin
from .models import Listing
admin.site.register(Listing)
 

Please note it shows only the title field because when we created the model we returned it


def __str__(self):
        return self.title

Custom view


class ListingAdmin(admin.ModelAdmin):
    list_display = ('id', 'title', 'is_published', 'price', 'list_date', 'realtor')
    list_display_links = ('id', 'title')
    list_filter = ('realtor',)
    list_editable = ('is_published','price')
    search_fields = ('title', 'description', 'city', 'state')
    list_per_page = 25

admin.site.register(Listing, ListingAdmin)

list_display = ( you list the fields you want to show

list_display_links = ( you list the fields you want them to be clickable

list_filter = ( you list the fields you want to make quick filter

list_editable = ( you list the fields you want them to be editable on the fly from the listings page

search_fields = (you list the fields you want them to be searchable

list_per_page = you define the number of listings you want to show per page

 width=