#16929 closed New feature (fixed)
Document how to extend UserAdmin with extra profile information
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Documentation | Version: | 1.3 |
Severity: | Normal | Keywords: | auth, admin |
Cc: | timograham@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I've been struggling to get this done, failing in the end and reverting to two separate admin sections; one for users and one for user profiles. It seems that the only way to properly include the UserProfile admin inside the User admin is by overwriting the standard User admin template and view. If that's really the case, I'd say it makes sense to, instead, automatically extend the User admin with the form that belongs to the AUTH_PROFILE_MODULE model, since there is a one to one relationship between the two anyway.
Attachments (1)
Change History (9)
comment:2 by , 13 years ago
Component: | contrib.auth → Documentation |
---|---|
Summary: | The form for AUTH_PROFILE_MODULE should extend the basic User admin page → Document how to extend UserAdmin with extra profile information |
Triage Stage: | Unreviewed → Accepted |
Automatically extending UserAdmin
would be a bit too magical. charettes has given a great example for how to properly extend UserAdmin
. This would be a nice addition to the documentation.
follow-up: 4 comment:3 by , 13 years ago
One issue with this is that if you had two apps that both attempted to add something (like an inline) to the UserAdmin, only one of them (the last in INSTALLED_APPS?) would take.
comment:4 by , 13 years ago
Replying to schinckel:
One issue with this is that if you had two apps that both attempted to add something (like an inline) to the UserAdmin, only one of them (the last in INSTALLED_APPS?) would take.
This might feel a bit hackish but you can do the following:
#my_nth_app/admin.py from django.contrib import admin from django.contrib.auth.admin import UserAdmin from django.contrib.auth.models import User from my_nth_app.models import MyNthAppModel class OneOfMyNthAppInline(admin.TabularInline): model = MyNthAppModel fk_name = 'user' #hackish RegisteredUserAdmin = admin.site._registry.get(User) class MyNthAppUserAdmin(RegisteredUserAdmin): inlines = RegisteredUserAdmin.inlines + [OneOfMyNthAppInline] # Re-register UserAdmin admin.site.unregister(User) admin.site.register(User, MyNthAppUserAdmin)
I know tickets aren't the right place to provide such examples but since it's the only way (I'm aware of) to achieve what @schinckel was trying to do without coupling all the apps I think it was worth posting until a proper solution can be documented.
comment:5 by , 13 years ago
Please can we add this to the documentation?
A link to this ticket at https://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users would have saved me half an hour searching.
by , 12 years ago
Attachment: | 16929.diff added |
---|
comment:6 by , 12 years ago
Cc: | added |
---|---|
Has patch: | set |
comment:7 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I think you can include the UserProfile admin inside the User admin doing the following: