Browse Source

Fixed #28667 -- Clarified how to override list of forms fields for custom UserAdmin with a custom user model.

swatantra 5 years ago
parent
commit
c13e3715f5
1 changed files with 24 additions and 0 deletions
  1. 24 0
      docs/topics/auth/customizing.txt

+ 24 - 0
docs/topics/auth/customizing.txt

@@ -880,6 +880,28 @@ override any of the definitions that refer to fields on
 ``django.contrib.auth.models.AbstractUser`` that aren't on your
 custom user class.
 
+.. note::
+
+    If you are using a custom ``ModelAdmin`` which is a subclass of
+    ``django.contrib.auth.admin.UserAdmin``, then you need to add your custom
+    fields to ``fieldsets`` (for fields to be used in editing users) and to
+    ``add_fieldsets`` (for fields to be used when creating a user). For
+    example::
+
+        from django.contrib.auth.admin import UserAdmin
+
+        class CustomUserAdmin(UserAdmin):
+            ...
+            fieldsets = UserAdmin.fieldsets + (
+                (None, {'fields': ('custom_field',)}),
+            )
+            add_fieldsets = UserAdmin.add_fieldsets + (
+                (None, {'fields': ('custom_field',)}),
+            )
+
+    See :ref:`a full example <custom-users-admin-full-example>` for more
+    details.
+
 Custom users and permissions
 ----------------------------
 
@@ -974,6 +996,8 @@ If your project uses proxy models, you must either modify the proxy to extend
 the user model that's in use in your project, or merge your proxy's behavior
 into your :class:`~django.contrib.auth.models.User` subclass.
 
+.. _custom-users-admin-full-example:
+
 A full example
 --------------