From: Stephen Finucane Date: Sat, 29 Oct 2016 13:18:28 +0000 (+0100) Subject: admin: Integrate UserProfile fields into admin X-Git-Tag: v2.0.0-rc1~160 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d5a1bf84e84aa4cb859c873a942593dda7095a7b;p=thirdparty%2Fpatchwork.git admin: Integrate UserProfile fields into admin 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 --- diff --git a/patchwork/admin.py b/patchwork/admin.py index ef041c4a..e80415a9 100644 --- a/patchwork/admin.py +++ b/patchwork/admin.py @@ -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)