admin 的请求流程:
1 启动:
import admin
def autodiscover():
autodiscover_modules('admin', register_to=site)
执行每一个app下的admin.py文件
2 注册,
3 设计URL
class ArticleConfig(admin.ModelAdmin):
def deletes(self):
return mark_safe("<a href="">删除</a>")
list_display = ["title", "desc", "create_time","nid",deletes] # 页面显示的字段及内容
list_display_links = ["title"] # 增加点击的再短
list_filter = ['title',"user"] # 右侧列表显示的 字段内容,可点击
list_editable = ["desc","nid"] # 在页面中修改
search_fields = ["title", "desc"] # 增加一个搜索框,模糊匹配字段内容
# change_list_template = "login.html" # 更改admin页面
fields = ("user",) # 点击字段,跳转到下个页面的内容
单例模式方式1 :__new__ class Singleton(object): _instance = None def __new__(cls, *args, **kw): if not cls._instance: cls._instance = super(Singleton, cls).__new__(cls, *args, **kw) return cls._instance class MyClass(Singleton): a = 1
方式2 导入模块
from mysingleton import my_singleton,My_Singleton my_singleton.foo() print(id(my_singleton))
- admin详情 : https://www.cnblogs.com/yuanchenqi/articles/8323452.html
class ArticleConfig(admin.ModelAdmin):
def deletes(self):
return mark_safe("<a href="">删除</a>")
list_display = ["title", "desc", "create_time","nid",deletes] # 页面显示的字段及内容
list_display_links = ["title"] # 增加点击的再短
list_filter = ['title',"user"] # 右侧列表显示的 字段内容,可点击
list_editable = ["desc","nid"] # 在页面中修改
search_fields = ["title", "desc"] # 增加一个搜索框,模糊匹配字段内容
# change_list_template = "login.html" # 更改admin页面
fields = ("user",) # 点击字段,跳转到下个页面的内容