Django - User, UserProfile, and Admin

后端 未结 3 2034
执念已碎
执念已碎 2020-12-04 18:29

I\'m trying to get the Django Admin interface to display information about my profile. It displays all of my users but no profile information. I\'m not quite sure how to g

3条回答
  •  天命终不由人
    2020-12-04 19:24

    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 admin
    from django.contrib.auth.models import User
    from django.contrib.auth.admin import UserAdmin
    from accounts.models import UserProfile
    
    admin.site.unregister(User)
    
    class UserProfileInline(admin.StackedInline):
        model = UserProfile
    
    class UserProfileAdmin(UserAdmin):
        inlines = [ UserProfileInline, ]
    
    admin.site.register(User, UserProfileAdmin)
    

提交回复
热议问题