[PATCH] admin: Integrate UserProfile fields into admin

Stephen Finucane stephen at that.guru
Sun Oct 30 00:18:28 AEDT 2016


The 'User' model is extended by means of a 'UserProfile' model. These
fields are not correctly displayed in the admin UI, but they should be.
Let's fix this per the recommendations of the Django docs [1].

[1] https://docs.djangoproject.com/en/1.10/topics/auth/customizing/#extending-the-existing-user-model

Signed-off-by: Stephen Finucane <stephen at that.guru>
---
 patchwork/admin.py | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/patchwork/admin.py b/patchwork/admin.py
index 85ffecf..57746b7 100644
--- a/patchwork/admin.py
+++ b/patchwork/admin.py
@@ -20,12 +20,26 @@
 from __future__ import absolute_import
 
 from django.contrib import admin
+from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
+from django.contrib.auth.models import User
 
 from patchwork.models import (Project, Person, UserProfile, State, Submission,
                               Patch, CoverLetter, Comment, Bundle, Tag, Check,
                               DelegationRule)
 
 
+class UserProfileInline(admin.StackedInline):
+    model = UserProfile
+    can_delete = False
+    verbose_name_plural = 'user profile'
+
+
+class UserAdmin(BaseUserAdmin):
+    inlines = (UserProfileInline, )
+admin.site.unregister(User)
+admin.site.register(User, UserAdmin)
+
+
 class DelegationRuleInline(admin.TabularInline):
     model = DelegationRule
     fields = ('path', 'user', 'priority')
@@ -52,11 +66,6 @@ class PersonAdmin(admin.ModelAdmin):
 admin.site.register(Person, PersonAdmin)
 
 
-class UserProfileAdmin(admin.ModelAdmin):
-    search_fields = ('user__username', 'user__first_name', 'user__last_name')
-admin.site.register(UserProfile, UserProfileAdmin)
-
-
 class StateAdmin(admin.ModelAdmin):
     list_display = ('name', 'action_required')
 admin.site.register(State, StateAdmin)
-- 
2.7.4



More information about the Patchwork mailing list