summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2012-09-15 07:37:33 -0400
committerTim Graham <timograham@gmail.com>2012-09-15 07:41:49 -0400
commit18d88a169fecf7efa2fba2ba2867e7a37084c7fc (patch)
tree21cfc47685f7850ca422919557bfb6036e3804c2 /docs
parent81c77d24eff8d97752681f413451a170861e865d (diff)
[1.4.x] Fixed #16929 - Documented how to extend UserAdmin with UserProfile fields; thanks charettes for the draft example.
Backport of 22242c510f84c53803afe2907649c892cb1b3d9a from master.
Diffstat (limited to 'docs')
-rw-r--r--docs/topics/auth.txt30
1 files changed, 30 insertions, 0 deletions
diff --git a/docs/topics/auth.txt b/docs/topics/auth.txt
index 35777d075e..efc6e78413 100644
--- a/docs/topics/auth.txt
+++ b/docs/topics/auth.txt
@@ -664,6 +664,36 @@ the handler, if ``created`` is ``True``, create the associated user profile::
.. seealso:: :doc:`/topics/signals` for more information on Django's signal
dispatcher.
+Adding UserProfile fields to the admin
+--------------------------------------
+
+To add the UserProfile fields to the user page in the admin, define an
+:class:`~django.contrib.admin.InlineModelAdmin` (for this example, we'll use a
+:class:`~django.contrib.admin.StackedInline`) in your app's ``admin.py`` and
+add it to a ``UserAdmin`` class which is registered with the
+:class:`~django.contrib.auth.models.User` class::
+
+ from django.contrib import admin
+ from django.contrib.auth.admin import UserAdmin
+ from django.contrib.auth.models import User
+
+ from my_user_profile_app.models import UserProfile
+
+ # Define an inline admin descriptor for UserProfile model
+ # which acts a bit like a singleton
+ class UserProfileInline(admin.StackedInline):
+ model = UserProfile
+ can_delete = False
+ verbose_name_plural = 'profile'
+
+ # Define a new User admin
+ class UserAdmin(UserAdmin):
+ inlines = (UserProfileInline, )
+
+ # Re-register UserAdmin
+ admin.site.unregister(User)
+ admin.site.register(User, UserAdmin)
+
Authentication in Web requests
==============================