Skip to content

Commit 2cd48e2

Browse files
docs: overriding the default admin site (#1082)
1 parent 342da3c commit 2cd48e2

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

docs/sites/index.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Custom sites
33
order: 11
4-
description: Custom admin sites for Unfold.
4+
description: Create and customize admin sites in Django Unfold, including overriding the default admin site and registering models with custom admin sites.
55
---
66

77
# Custom sites
@@ -10,6 +10,7 @@ In order to create a custom admin site, Unfold provides the `unfold.sites.Unfold
1010

1111
```python
1212
# sites.py
13+
1314
from django.contrib import admin
1415
from unfold.sites import UnfoldAdminSite
1516

@@ -26,6 +27,7 @@ custom_admin_site = CustomAdminSite(name="custom_admin_site")
2627
from django.urls import path
2728
from .sites import custom_admin_site
2829

30+
2931
urlpatterns = [
3032
# other URL patterns
3133
path("admin/", custom_admin_site.urls),
@@ -38,9 +40,35 @@ urlpatterns = [
3840
from django.contrib.auth.models import User
3941
from unfold.admin import ModelAdmin
4042

43+
4144
@admin.register(User, site=custom_admin_site)
4245
class UserAdmin(ModelAdmin):
4346
model = User
4447
```
4548

46-
Note: If you use the default `django.contrib.admin.AdminSite` you will receive a `NoReverseMatch` error because the default admin site does not contain all URL patterns required by Unfold.
49+
**Note**: If you use the default `django.contrib.admin.AdminSite` you will receive a `NoReverseMatch` error because the default admin site does not contain all URL patterns required by Unfold.
50+
51+
## Overriding the default admin site
52+
53+
If you want to override the default admin site by setting the `default_site` attribute of a custom `django.contrib.admin.apps.AdminConfig` class, you must install Unfold using `unfold.apps.AppConfig` instead of just `unfold` in `INSTALLED_APPS`.
54+
55+
```python
56+
# settings.py
57+
58+
INSTALLED_APPS = [
59+
"unfold.apps.BasicAppConfig", # App config not overriding `django.contrib.admin.site`
60+
# some other apps
61+
"django.contrib.admin",
62+
"your_app",
63+
]
64+
```
65+
66+
```python
67+
# apps.py
68+
69+
from django.contrib.admin.apps import AdminConfig
70+
71+
72+
class MyAdminConfig(AdminConfig):
73+
default_site = "myproject.sites.CustomAdminSite"
74+
```

0 commit comments

Comments
 (0)