-
還有一個裝飾器用於注冊您的
ModelAdmin類:from django.contrib import admin from .models import Author @admin.register(Author) class AuthorAdmin(admin.ModelAdmin): pass給它一個或多個模型類來注冊
ModelAdmin。如果您使用自定義,請使用AdminSitesite關鍵字參數傳遞它:from django.contrib import admin from .models import Author, Editor, Reader from myproject.admin_site import custom_admin_site @admin.register(Author, Reader, Editor, site=custom_admin_site) class PersonAdmin(admin.ModelAdmin): pass如果您必須在
__init__()方法中引用模型管理類,則不能使用此裝飾器,例如super(PersonAdmin, self).__init__(*args, **kwargs)。您可以使用super().__init__(*args, **kwargs)。
本文介紹 django.contrib.admin.register 的用法。
聲明
register(*models, site=django.contrib.admin.sites.site)
相關用法
- Python Numpy recarray.tostring()用法及代碼示例
- Python reduce()用法及代碼示例
- Python response.status_code用法及代碼示例
- Python Numpy recarray.tobytes()用法及代碼示例
- Python Numpy recarray.min()用法及代碼示例
- Python response.request用法及代碼示例
- Python Numpy recarray.cumprod()用法及代碼示例
- Python re.compile用法及代碼示例
- Python Django re_path用法及代碼示例
- Python response.elapsed用法及代碼示例
- Python response.cookies用法及代碼示例
- Python response.ok用法及代碼示例
- Python Numpy recarray.argmin()用法及代碼示例
- Python Numpy recarray.cumsum()用法及代碼示例
- Python re.fullmatch()用法及代碼示例
- Python Django require_http_methods用法及代碼示例
- Python re.Match.start用法及代碼示例
- Python repr()用法及代碼示例
- Python re.split用法及代碼示例
- Python re.Match.groupdict用法及代碼示例
- Python Numpy recarray.tolist()用法及代碼示例
- Python response.text用法及代碼示例
- Python Numpy recarray.all()用法及代碼示例
- Python Numpy recarray.ptp()用法及代碼示例
- Python re.Pattern.match用法及代碼示例
注:本文由純淨天空篩選整理自djangoproject.com大神的英文原創作品 django.contrib.admin.register。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
