mirror of
https://github.com/jazzband/django-admin2.git
synced 2026-03-28 03:50:26 +00:00
Merge pull request #66 from RaphaelKimmig/add-admin2-core-documentation
add some docstrings to core.Admin2
This commit is contained in:
commit
0fd10cdbb9
1 changed files with 25 additions and 1 deletions
|
|
@ -9,6 +9,13 @@ from . import views
|
|||
|
||||
|
||||
class Admin2(object):
|
||||
"""
|
||||
The base Admin2 object.
|
||||
It keeps a registry of all registered Models and collects the urls of their
|
||||
related ModelAdmin2 instances.
|
||||
|
||||
It also provides an index view that serves as an entry point to the admin site.
|
||||
"""
|
||||
index_view = views.IndexView
|
||||
|
||||
def __init__(self, name='admin2'):
|
||||
|
|
@ -16,6 +23,15 @@ class Admin2(object):
|
|||
self.name = name
|
||||
|
||||
def register(self, model, modeladmin=None, **kwargs):
|
||||
"""
|
||||
Registers the given model with the given admin class.
|
||||
|
||||
If no modeladmin is passed, it will use ModelAdmin2. If keyword
|
||||
arguments are given they will be passed to the admin class on
|
||||
instantiation.
|
||||
|
||||
If a model is already registered, this will raise ImproperlyConfigured.
|
||||
"""
|
||||
if model in self.registry:
|
||||
raise ImproperlyConfigured
|
||||
if not modeladmin:
|
||||
|
|
@ -23,13 +39,21 @@ class Admin2(object):
|
|||
self.registry[model] = modeladmin(model, **kwargs)
|
||||
|
||||
def deregister(self, model):
|
||||
"""
|
||||
Deregisters the given model.
|
||||
|
||||
If the model is not already registered, this will raise ImproperlyConfigured.
|
||||
"""
|
||||
try:
|
||||
del self.registry[model]
|
||||
except KeyError:
|
||||
raise ImproperlyConfigured
|
||||
|
||||
def autodiscover(self):
|
||||
apps = []
|
||||
"""
|
||||
Autodiscovers all admin2.py modules for apps in INSTALLED_APPS by
|
||||
trying to import them.
|
||||
"""
|
||||
for app_name in [x for x in settings.INSTALLED_APPS]:
|
||||
try:
|
||||
import_module("%s.admin2" % app_name)
|
||||
|
|
|
|||
Loading…
Reference in a new issue