Combining User and UserProfile in the admin

后端 未结 1 544
既然无缘
既然无缘 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)
提交回复
热议问题