mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #19414 -- Added admin registration decorator
Thanks stavros for the suggestion.
This commit is contained in:
committed by
Tim Graham
parent
d1c9802811
commit
98514849dc
@@ -101,6 +101,34 @@ Other topics
|
||||
|
||||
admin.site.register(Author)
|
||||
|
||||
The register decorator
|
||||
----------------------
|
||||
|
||||
.. function:: register(*models, [site=django.admin.sites.site])
|
||||
|
||||
.. versionadded:: 1.7
|
||||
|
||||
There is also a decorator for registering your ``ModelAdmin`` classes::
|
||||
|
||||
from django.contrib import admin
|
||||
from .models import Author
|
||||
|
||||
@admin.register(Author)
|
||||
class AuthorAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
It is given one or more model classes to register with the ``ModelAdmin``
|
||||
and an optional keyword argument ``site`` if you are not using the default
|
||||
``AdminSite``::
|
||||
|
||||
from django.contrib import admin
|
||||
from .models import Author, Reader, Editor
|
||||
from myproject.admin_site import custom_admin_site
|
||||
|
||||
@admin.register(Author, Reader, Editor, site=custom_admin_site)
|
||||
class PersonAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
``ModelAdmin`` options
|
||||
----------------------
|
||||
|
||||
|
||||
@@ -135,6 +135,10 @@ Minor features
|
||||
customize the value of :attr:`ModelAdmin.fields
|
||||
<django.contrib.admin.ModelAdmin.fields>`.
|
||||
|
||||
* In addition to the existing ``admin.site.register`` syntax, you can use the
|
||||
new :func:`~django.contrib.admin.register` decorator to register a
|
||||
:class:`~django.contrib.admin.ModelAdmin`.
|
||||
|
||||
:mod:`django.contrib.auth`
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
||||
Reference in New Issue
Block a user