Skip to content

Commit

Permalink
docs: user form (#931)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasvinclav authored Jan 4, 2025
1 parent 8f02f37 commit 1711c03
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions docs/installation/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description: User & group models configuration

By default, when `django.contrib.auth` is in `INSTALLED_APPS`, you are going to have user and group models in admin. Both models are going to work but they will look unstyled because they are not inheriting from `unfold.admin.ModelAdmin`.

The solution is to unregister default admin classes and then register them back by using `unfold.admin.ModelAdmin` like in the example below
The solution is to unregister default admin classes and then register them back by using `unfold.admin.ModelAdmin` like in the example below. Additionally, we have to override default user forms (`UserAdmin` class) which are by default loaded by Django admin. New, overridden forms are going to have proper styling.

```python
# admin.py
Expand All @@ -18,6 +18,7 @@ from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.contrib.auth.admin import GroupAdmin as BaseGroupAdmin
from django.contrib.auth.models import User, Group

from unfold.forms import AdminPasswordChangeForm, UserChangeForm, UserCreationForm
from unfold.admin import ModelAdmin


Expand All @@ -27,7 +28,10 @@ admin.site.unregister(Group)

@admin.register(User)
class UserAdmin(BaseUserAdmin, ModelAdmin):
pass
# Forms loaded from `unfold.forms`
form = UserChangeForm
add_form = UserCreationForm
change_password_form = AdminPasswordChangeForm


@admin.register(Group)
Expand Down

0 comments on commit 1711c03

Please sign in to comment.