I saw a lot of questions differently that have something like the following:
class UserProfileInline(admin.StackedInline): model = UserProfile can_delete = False verbose_name_plural = 'profile' class NewUserAdmin(UserAdmin): inlines = (UserProfileInline, ) admin.site.unregister(User) admin.site.register(User, NewUserAdmin)
What I want to do is the opposite, but I don’t see it working. Here the code that I have does not work.
from django.contrib import admin from django.contrib.auth.admin import UserAdmin from django.contrib.auth.models import User from myapp.models import SpecialUserType class UserInline(admin.StackedInline): model = User can_delete = False class IncludeUserAdmin(admin.ModelAdmin): inlines = (UserInline,) admin.register(SpecialUserType, IncludeUserAdmin)
How can I do this work so that User built into admin SpecialUserType ?
The error I am getting is:
<class 'django.contrib.auth.models.User'> has no ForeignKey to <class 'students.models.SpecialUserType'>
This makes sense because OneToOneField is located in the SpecialUserType model, obviously, and not in the User . But how can I make it reverse on OneToOneField ?
(I know this may seem unusual, but there is a good reason why I want to configure the administrator this way, and not vice versa).
source share