标签:com color registry hang hoc auth 对象 pre .com
(1) 启动
autodiscover_modules(‘admin‘, register_to=site)
(2) 注册
单例模式
admin.site=AdminSite(): 单例对象
class AdminSite(object):
def __init__(self, name=‘admin‘):
self._registry = {}
def register(self, model, admin_class=None, **options):
if not admin_class:
admin_class = ModelAdmin
self._registry[model] = admin_class(model, self) # {Book:ModelAdmin(Book)}
admin.site.register(Book) # admin.site._registry={Book:ModelAdmin(Book)}
admin.site.register(Publish) # admin.site._registry={Book:ModelAdmin(Book),Publish:ModelAdmin(Publish)}
class Authoconfig(admin.ModelAdmin):
pass
admin.site.register(Author,Authoconfig) # admin.site._registry={Book:ModelAdmin(Book),Publish:ModelAdmin(Publish),Author:Authoconfig(Author)}
为每个app下的model设计增删改查4个URL,以book为例。
127.0.0.1:8000/admin/app01/book/
127.0.0.1:8000/admin/app01/book/add
127.0.0.1:8000/admin/app01/book/1/change/
127.0.0.1:8000/admin/app01/book/1/delete
案例
标签:com color registry hang hoc auth 对象 pre .com
原文地址:https://www.cnblogs.com/mengbin0546/p/9126817.html