Author: brosner
Date: 2008-07-09 11:01:33 -0500 (Wed, 09 Jul 2008)
New Revision: 7872

Modified:
   django/branches/newforms-admin/django/contrib/admin/__init__.py
   django/branches/newforms-admin/docs/admin.txt
Log:
newforms-admin: Added autodiscover functionality to django.contrib.admin. This 
makes the admin aware of per-app admin.py modules and does an import on them 
when explicitly called. Docs show how this is used. Fixed #6003, #6776, #6776.

Modified: django/branches/newforms-admin/django/contrib/admin/__init__.py
===================================================================
--- django/branches/newforms-admin/django/contrib/admin/__init__.py     
2008-07-08 21:53:38 UTC (rev 7871)
+++ django/branches/newforms-admin/django/contrib/admin/__init__.py     
2008-07-09 16:01:33 UTC (rev 7872)
@@ -1,3 +1,16 @@
 from django.contrib.admin.options import ModelAdmin, HORIZONTAL, VERTICAL
 from django.contrib.admin.options import StackedInline, TabularInline
 from django.contrib.admin.sites import AdminSite, site
+
+def autodiscover():
+    """
+    Auto-discover INSTALLED_APPS admin.py modules and fail silently when 
+    not present. This forces an import on them to register any admin bits they
+    may want.
+    """
+    from django.conf import settings
+    for app in settings.INSTALLED_APPS:
+        try:
+            __import__("%s.admin" % app)
+        except ImportError:
+            pass

Modified: django/branches/newforms-admin/docs/admin.txt
===================================================================
--- django/branches/newforms-admin/docs/admin.txt       2008-07-08 21:53:38 UTC 
(rev 7871)
+++ django/branches/newforms-admin/docs/admin.txt       2008-07-09 16:01:33 UTC 
(rev 7872)
@@ -609,11 +609,16 @@
     # urls.py
     from django.conf.urls.defaults import *
     from django.contrib import admin
+    
+    admin.autodiscover()
 
     urlpatterns = patterns('',
         ('^admin/(.*)', admin.site.root),
     )
 
+Above we used ``admin.autodiscover()`` to automatically load the
+``INSTALLED_APPS`` admin.py modules.
+
 In this example, we register the ``AdminSite`` instance
 ``myproject.admin.admin_site`` at the URL ``/myadmin/`` ::
 
@@ -625,6 +630,10 @@
         ('^myadmin/(.*)', admin_site.root),
     )
 
+There is really no need to use autodiscover when using your own ``AdminSite``
+instance since you will likely be importing all the per-app admin.py modules
+in your ``myproject.admin`` module.
+
 Note that the regular expression in the URLpattern *must* group everything in
 the URL that comes after the URL root -- hence the ``(.*)`` in these examples.
 


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to