diff mbox

Streamline admin model registration

Message ID 1301677935-18803-1-git-send-email-halsmit@t-online.de
State Accepted
Commit c50379dda534564eb5701d8c007910bc1ee7e066
Headers show

Commit Message

Dirk Wallenstein April 1, 2011, 5:12 p.m. UTC
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@t-online.de>
---
 apps/patchwork/admin.py |   26 +++++++-------------------
 apps/urls.py            |    6 ++++--
 2 files changed, 11 insertions(+), 21 deletions(-)

Comments

Jeremy Kerr April 14, 2011, 7:14 a.m. UTC | #1
Hi Dirk,

> 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/

Thanks, applied.


Jeremy
diff mbox

Patch

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'}),