18、Django自定义页面跳转链接
model.py
# 空内容model
class Feedback_Stat(models.Model):
pass
admin.py
# 重写了modeladmin负责默认页面渲染行为的changelist_view函数实现了对自定义页面的渲染:
from django.contrib import admin
from django.shortcuts import render
from models import Feedback, Feedback_Stat
from views import feedback_stats
@admin.register(Feedback_Stat)
class FeedbackStatsAdmin(admin.ModelAdmin):
def changelist_view(self, request, extra_content=None):
return feedback_stats(request)
# 由于重写了其 changelist_view 方法,其将会跳转到用户自定义的 feedback_stats 页面
或者
class MyAdminSite(admin.AdminSite):
def get_app_list(self,request):
app_list = super().get_app_list(request)
app_list + = [
{
" name":"我的自定义应用程序",
" app_label": " my_test_app",
#" app_url":"/admin/test_view",
" models":[
{
" name":" tcptraceroute",
" object_name":" tcptraceroute",
" admin_url":" /admin/test_view",
" view_only":True,
}
],
}
]
return app_list
Last updated