Admin
Admin
Register Models in Admin
from django.contrib import admin
from .models import ExampleModel
@admin.register(ExampleModel)
class ExampleModelAdmin(admin.ModelAdmin):
= ('name', 'description')
list_display = ('name',) search_fields
Customize Admin Interface
ModelAdmin Options
from django.contrib import admin
from .models import ExampleModel
@admin.register(ExampleModel)
class ExampleModelAdmin(admin.ModelAdmin):
= ('name', 'description')
list_display = ('name',)
search_fields = ('name',)
list_filter = ('name',)
ordering = ('name', 'description')
fields = ('created_at',) readonly_fields
Inlines
from django.contrib import admin
from .models import ExampleModel, RelatedModel
class RelatedModelInline(admin.TabularInline):
= RelatedModel
model = 1
extra
@admin.register(ExampleModel)
class ExampleModelAdmin(admin.ModelAdmin):
= [RelatedModelInline] inlines
Custom Actions
from django.contrib import admin
from .models import ExampleModel
@admin.register(ExampleModel)
class ExampleModelAdmin(admin.ModelAdmin):
= ['make_published']
actions
def make_published(self, request, queryset):
='published')
queryset.update(status= "Mark selected stories as published" make_published.short_description