Combining User and UserProfile in the admin

后端 未结 1 546
既然无缘
既然无缘 2021-02-04 17:03

I have been reading up on Django\'s separation of Users and Profiles, and I have decided to go with a model called UserProfile that is located in an Accounts app as my Profile.

相关标签:
1条回答
  • 2021-02-04 17:37

    You can do this by using inline admin models

    before writing your custom User admin you have to unregister the already registered User admin

    admin.site.unregister(User)
    

    define the Inline UserProfile

    class UserProfileInline(admin.TabularInline):
        model = UserProfile
    

    and use the inline in the User admin

    class UserAdmin(admin.ModelAdmin):
        inlines = [UserProfileInline]
    admin.site.register(User, UserAdmin)
    
    0 讨论(0)
提交回复
热议问题