You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+40Lines changed: 40 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,6 +57,7 @@ Did you decide to start using Unfold but you don't have time to make the switch
57
57
-[Dropdown filters](#dropdown-filters)
58
58
-[Numeric filters](#numeric-filters)
59
59
-[Date/time filters](#datetime-filters)
60
+
-[Custom admin pages](#custom-admin-pages)
60
61
-[Nonrelated inlines](#nonrelated-inlines)
61
62
-[Display decorator](#display-decorator)
62
63
-[Change form tabs](#change-form-tabs)
@@ -621,6 +622,45 @@ class YourModelAdmin(ModelAdmin):
621
622
)
622
623
```
623
624
625
+
## Custom admin pages
626
+
627
+
By default, Unfold provides a basic view mixin which helps with creation of basic views which are part of Unfold UI. The implementation requires creation of class based view inheriting from `unfold.views.UnfoldModelAdminViewMixin`. It is important to add `title` and `permissions_required` properties.
628
+
629
+
```python
630
+
# admin.py
631
+
632
+
from django.views.generic import TemplateView
633
+
from unfold.admin import ModelAdmin
634
+
from unfold.views import UnfoldModelAdminViewMixin
title ="Custom Title"# required: custom page header title
639
+
permissions_required = () # required: tuple of permissions
640
+
template_name ="some/template/path.html"
641
+
642
+
643
+
classCustomAdmin(ModelAdmin):
644
+
defget_urls(self):
645
+
returnsuper().get_urls() + [
646
+
path(
647
+
"custom-url-path",
648
+
MyClassBasedView.as_view(model_admin=self), # IMPORTANT: model_admin is required
649
+
name="custom_name"
650
+
),
651
+
]
652
+
```
653
+
654
+
The template is straightforward, extend from `unfold/layouts/base.html` and the UI will display all Unfold components like header or sidebar with all menu items. Then all content needs to be located in `content` block.
655
+
656
+
```django-html
657
+
{% extends "unfold/layouts/base.html" %}
658
+
659
+
{% block content %}
660
+
Content here
661
+
{% endblock %}
662
+
```
663
+
624
664
## Nonrelated inlines
625
665
626
666
To display inlines which are not related (no foreign key pointing at the main model) to the model instance in changeform, you can use nonrelated inlines which are included in `unfold.contrib.inlines` module. Make sure this module is included in `INSTALLED_APPS` in settings.py.
0 commit comments