[PATCH] Embellish admin model change lists

Dirk Wallenstein halsmit at t-online.de
Tue Jan 18 21:16:00 EST 2011


Add fields to the admin change list pages of patchwork models, and add
filters and search boxes where appropriate.

Signed-off-by: Dirk Wallenstein <halsmit at t-online.de>
---
 apps/patchwork/admin.py |   33 ++++++++++++++++++++++++++-------
 1 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/apps/patchwork/admin.py b/apps/patchwork/admin.py
index 2cf1bdc..7629401 100644
--- a/apps/patchwork/admin.py
+++ b/apps/patchwork/admin.py
@@ -8,31 +8,50 @@ from patchwork.models import Project, Person, UserProfile, State, Patch, \
 admin_site = admin.AdminSite()
 
 class ProjectAdmin(admin.ModelAdmin):
-    pass
+    list_display = ('name', 'linkname','listid', 'listemail')
 admin_site.register(Project, ProjectAdmin)
 
 class PersonAdmin(admin.ModelAdmin):
-    pass
+    list_display = ('__unicode__', 'has_account')
+    search_fields = ('name', 'email')
+    def has_account(self, person):
+        return bool(person.user)
+    has_account.boolean = True
+    has_account.admin_order_field = 'user'
+    has_account.short_description = 'Account'
 admin_site.register(Person, PersonAdmin)
 
 class UserProfileAdmin(admin.ModelAdmin):
-    pass
+    search_fields = ('user__first_name', 'user__last_name')
 admin_site.register(UserProfile, UserProfileAdmin)
 
 class StateAdmin(admin.ModelAdmin):
-    pass
+    list_display = ('name', 'action_required')
 admin_site.register(State, StateAdmin)
 
 class PatchAdmin(admin.ModelAdmin):
-    pass
+    list_display = ('name', 'submitter', 'project', 'state', 'date',
+            'archived', 'is_pull_request')
+    list_filter = ('project', 'state', 'archived')
+    search_fields = ('name', 'submitter__name', 'submitter__email')
+    date_hierarchy = 'date'
+    def is_pull_request(self, patch):
+        return bool(patch.pull_url)
+    is_pull_request.boolean = True
+    is_pull_request.admin_order_field = 'pull_url'
+    is_pull_request.short_description = 'Pull'
 admin_site.register(Patch, PatchAdmin)
 
 class CommentAdmin(admin.ModelAdmin):
-    pass
+    list_display = ('patch', 'submitter', 'date')
+    search_fields = ('patch__name', 'submitter__name', 'submitter__email')
+    date_hierarchy = 'date'
 admin_site.register(Comment, CommentAdmin)
 
 class BundleAdmin(admin.ModelAdmin):
-    pass
+    list_display = ('name', 'owner', 'project', 'public')
+    list_filter = ('public', 'project')
+    search_fields = ('name', 'owner')
 admin_site.register(Bundle, BundleAdmin)
 
 admin_site.register(User, UserAdmin)
-- 
1.7.3.2



More information about the Patchwork mailing list