Note_Tech

All technological notes.


Project maintained by simonangel-fong Hosted on GitHub Pages — Theme by mattgraham

Django - Admin

Back


AdminSite

Method Description
site_header The text to put at the top of each admin page
site_title admin page’s <title>
Method Description
register() Registers the given model class with the given admin_class.

ModelAdmin

Attribute Description
fields layout the field in the forms on the “add” and “change” pages
list_display fields are displayed on the change list page of the admin.
list_editable a list of field names on the model which will allow editing on the change list page.
list_filter activate filters in the right sidebar of the change list page of the admin.
search_fields enable a search box on the admin change list page.

Example

from django.contrib import admin
from .models import Blog, Hashtag
# Register your models here.


class BlogAdmin(admin.ModelAdmin):
    fields = ("title", "author", "content",)
    list_display = ("title", "author", "created_time", "published_time")
    list_editable = ("author",)
    list_filter = ("author",)
    search_fields = ("title", "content",)


admin.site.site_title = "Blog Admin"
admin.site.site_header = "Blog Admin"
admin.site.register(Blog, BlogAdmin)
admin.site.register(Hashtag)

login

login


Top