[PATCH] Streamline admin model registration

Dirk Wallenstein halsmit at t-online.de
Sat Apr 2 04:12:15 EST 2011


Use autodiscover and the new way to hook AdminSite into the URLconf.
AdminSite.root() will be removed in Django-1.3 as noted here:
http://docs.djangoproject.com/en/dev/internals/deprecation/

Signed-off-by: Dirk Wallenstein <halsmit at t-online.de>
---
 apps/patchwork/admin.py |   26 +++++++-------------------
 apps/urls.py            |    6 ++++--
 2 files changed, 11 insertions(+), 21 deletions(-)

diff --git a/apps/patchwork/admin.py b/apps/patchwork/admin.py
index 9f89df7..5297903 100644
--- a/apps/patchwork/admin.py
+++ b/apps/patchwork/admin.py
@@ -1,15 +1,10 @@
 from django.contrib import admin
-from django.contrib.sites.models import Site
-from django.contrib.auth.models import User
-from django.contrib.auth.admin import UserAdmin
 from patchwork.models import Project, Person, UserProfile, State, Patch, \
          Comment, Bundle
 
-admin_site = admin.AdminSite()
-
 class ProjectAdmin(admin.ModelAdmin):
     list_display = ('name', 'linkname','listid', 'listemail')
-admin_site.register(Project, ProjectAdmin)
+admin.site.register(Project, ProjectAdmin)
 
 class PersonAdmin(admin.ModelAdmin):
     list_display = ('__unicode__', 'has_account')
@@ -19,15 +14,15 @@ class PersonAdmin(admin.ModelAdmin):
     has_account.boolean = True
     has_account.admin_order_field = 'user'
     has_account.short_description = 'Account'
-admin_site.register(Person, PersonAdmin)
+admin.site.register(Person, PersonAdmin)
 
 class UserProfileAdmin(admin.ModelAdmin):
     search_fields = ('user__username', 'user__first_name', 'user__last_name')
-admin_site.register(UserProfile, UserProfileAdmin)
+admin.site.register(UserProfile, UserProfileAdmin)
 
 class StateAdmin(admin.ModelAdmin):
     list_display = ('name', 'action_required')
-admin_site.register(State, StateAdmin)
+admin.site.register(State, StateAdmin)
 
 class PatchAdmin(admin.ModelAdmin):
     list_display = ('name', 'submitter', 'project', 'state', 'date',
@@ -40,23 +35,16 @@ class PatchAdmin(admin.ModelAdmin):
     is_pull_request.boolean = True
     is_pull_request.admin_order_field = 'pull_url'
     is_pull_request.short_description = 'Pull'
-admin_site.register(Patch, PatchAdmin)
+admin.site.register(Patch, PatchAdmin)
 
 class CommentAdmin(admin.ModelAdmin):
     list_display = ('patch', 'submitter', 'date')
     search_fields = ('patch__name', 'submitter__name', 'submitter__email')
     date_hierarchy = 'date'
-admin_site.register(Comment, CommentAdmin)
+admin.site.register(Comment, CommentAdmin)
 
 class BundleAdmin(admin.ModelAdmin):
     list_display = ('name', 'owner', 'project', 'public')
     list_filter = ('public', 'project')
     search_fields = ('name', 'owner')
-admin_site.register(Bundle, BundleAdmin)
-
-admin_site.register(User, UserAdmin)
-
-class SiteAdmin(admin.ModelAdmin):
-    pass
-admin_site.register(Site, SiteAdmin)
-
+admin.site.register(Bundle, BundleAdmin)
diff --git a/apps/urls.py b/apps/urls.py
index 14f0545..51d95c3 100644
--- a/apps/urls.py
+++ b/apps/urls.py
@@ -19,11 +19,13 @@
 
 from django.conf.urls.defaults import *
 from django.conf import settings
-from patchwork.admin import admin_site
+from django.contrib import admin
 
 from registration.views import register
 from patchwork.forms import RegistrationForm
 
+admin.autodiscover()
+
 urlpatterns = patterns('',
     # Example:
     (r'^', include('patchwork.urls')),
@@ -36,7 +38,7 @@ urlpatterns = patterns('',
     (r'^accounts/', include('registration.urls')),
 
     # Uncomment this for admin:
-     (r'^admin/(.*)', admin_site.root),
+     (r'^admin/', include(admin.site.urls)),
 
      (r'^css/(?P<path>.*)$', 'django.views.static.serve',
         {'document_root': '/srv/patchwork/htdocs/css'}),
-- 
1.7.4



More information about the Patchwork mailing list