Patchwork Embellish admin model change lists

login
register
mail settings
Submitter Dirk Wallenstein
Date Jan. 18, 2011, 10:16 a.m.
Message ID <1295345760-9582-1-git-send-email-halsmit@t-online.de>
Download mbox | patch
Permalink /patch/79281/
State Accepted
Headers show

Comments

Dirk Wallenstein - Jan. 18, 2011, 10:16 a.m.
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@t-online.de>
---
 apps/patchwork/admin.py |   33 ++++++++++++++++++++++++++-------
 1 files changed, 26 insertions(+), 7 deletions(-)
Jeremy Kerr - Feb. 11, 2011, 1:55 a.m.
Hi Dirk,

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

Applied, with one change:

>  class UserProfileAdmin(admin.ModelAdmin):
> -    pass
> +    search_fields = ('user__first_name', 'user__last_name')

I've added user__username to this list, as I often need to lookup by username 
too.

Cheers,


Jeremy

Patch

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)