Django - User, UserProfile, and Admin Django - User, UserProfile, and Admin django django

Django - User, UserProfile, and Admin


I can't see exactly what's wrong, but here's a slightly simpler example that I know works. Put this is any working admin.py. Try adding a trailing comma to your inline-- some things break without it.

from django.contrib import adminfrom django.contrib.auth.models import Userfrom django.contrib.auth.admin import UserAdminfrom accounts.models import UserProfileadmin.site.unregister(User)class UserProfileInline(admin.StackedInline):    model = UserProfileclass UserProfileAdmin(UserAdmin):    inlines = [ UserProfileInline, ]admin.site.register(User, UserProfileAdmin)


This is not exactly an answer to your question BUT, according to Django Admin documentation, you can display information from UserProfile in your User "table". And you can make it searchable.

That would look something like this (modifying answer from C. Alan Zoppa):

class UserProfileAdmin(UserAdmin):    inlines = [ UserProfileInline, ]    def company(self, obj):        try:            return obj.get_profile().company        except UserProfile.DoesNotExist:            return ''    list_display = UserAdmin.list_display + ('company',)    search_fields = UserAdmin.search_fields + ('userprofile__company',)

You might have an issue though with search if your profile class is no longer called UserProfile.


The missing comma shouldn't matter. I suspect the problem is that you added a new admin.py but the development server didn't recognize it. If you restart the development server, it'll see the new file.