django admin customization code example

Example 1: django admin customization

# project/urls.py
admin.site.site_header = “Your Admin Heading”
admin.site.site_title = “Your Admin Portal"
admin.site.index_title = "Welcome to Admin Portal"

Example 2: django admin register

from django.contrib import admin
from .models import Author

@admin.register(Author)
class AuthorAdmin(admin.ModelAdmin):
    pass

Example 3: show post id on django admin interface

class BookAdmin(admin.ModelAdmin):
    readonly_fields = ('id',)

admin.site.register(Book, BookAdmin)

Example 4: what is admin.tabularinline django

from django.contrib import admin

class BookInline(admin.TabularInline):
    model = Book

class AuthorAdmin(admin.ModelAdmin):
    inlines = [
        BookInline,
    ]

Example 5: what is admin.tabularinline django

from django.db import models

class Author(models.Model):
   name = models.CharField(max_length=100)

class Book(models.Model):
   author = models.ForeignKey(Author, on_delete=models.CASCADE)
   title = models.CharField(max_length=100)