]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
admin: Integrate UserProfile fields into admin
authorStephen Finucane <stephen@that.guru>
Sat, 29 Oct 2016 13:18:28 +0000 (14:18 +0100)
committerStephen Finucane <stephen@that.guru>
Sat, 19 Nov 2016 18:32:45 +0000 (18:32 +0000)
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@that.guru>
patchwork/admin.py

index ef041c4a38320716a0dbb8bca8287a8760bf1d3f..e80415a90867befb6ef9cf0721f0769d603a6888 100644 (file)
@@ -20,6 +20,8 @@
 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 Bundle
 from patchwork.models import Check
@@ -37,6 +39,18 @@ from patchwork.models import Tag
 from patchwork.models import UserProfile
 
 
+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')
@@ -63,11 +77,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)