I have a search model
which has a ForeignKey
relation to User
class Searches(models.Model):
user = models.ForeignKey(User)
......
I have a UserProfile
model which has a OnetoOne
Relationship to User
class UserProfile(models.Model):
user = models.OneToOneField(User)
photo = models.ImageField(upload_to='profile_images', blank=True)
ispublic=models.NullBooleanField()
I have attached UserProfile
in admin.py
as follows:
class UserProfileInline(admin.StackedInline):
model = UserProfile
can_delete = False
class UserProfileAdmin(UserAdmin):
inlines=(UserProfileInline, )
list_filter = UserAdmin.list_filter + ('email',)
list_display=('username','email','first_name','last_name','isPublic')
admin.site.unregister(get_user_model())
admin.site.register(get_user_model(), UserProfileAdmin)
Now I do not see a separate UserProfile
but is integrated into User
, which is what I want.
I also want to have Search
model to show up in User
admin. But also seperately.
how can I register two (or more) Admins
to User
model?
Try just putting another
Inline
inside theUserProfileAdmin
, that will then place theUserProfileInline
andSearchesInline
in theUserProfileAdmin
, then putadmin.site.register(Searches)
inadmin.py
. Unless I misunderstand the question.