Document how to add non-ModelAdmin views to a ModelAdminGroup (#10022)

pull/10071/head
Onno T 2023-02-04 18:02:07 +01:00 zatwierdzone przez Matt Westcott
rodzic a2e1becc49
commit 4d9f4898de
4 zmienionych plików z 40 dodań i 1 usunięć

Wyświetl plik

@ -4,6 +4,7 @@ Changelog
5.1 (xx.xx.xxxx) - IN DEVELOPMENT
~~~~~~~~~~~~~~~~
* Docs: Document how to add non-ModelAdmin views to a `ModelAdminGroup` (Onno Timmerman)
* Maintenance: Switch to ruff for flake8 / isort code checking (Oliver Parker)

Wyświetl plik

@ -8,4 +8,5 @@ maxdepth: 1
---
custom_clean
reversing_urls
modeladmingroup_extra_views
```

Wyświetl plik

@ -0,0 +1,37 @@
# Adding non-ModelAdmin views to a `ModelAdminGroup`
To add menu items to a `ModelAdminGroup` that are not managed by ModelAdmin, you can override the `get_submenu_items` method. For example, to add the calendar view described in [](../../../../extending/admin_views) alongside an `EventAdmin` modeladmin, you would do the following (in place of registering it through the `register_admin_menu_item` hook):
```{code-block} python
from django.urls import reverse
from wagtail.contrib.modeladmin.options import (
ModelAdmin,
modeladmin_register,
ModelAdminGroup,
)
from wagtail.admin.menu import MenuItem
class EventAdmin(ModelAdmin):
model = CalendarEvent
menu_label = "Events"
menu_icon = "date"
menu_order = 200
list_display = ('title', 'date')
class CalendarGroup(ModelAdminGroup):
menu_label = "Calendar events"
menu_icon = "folder-open-inverse"
menu_order = 900
items = (EventAdmin,)
def get_submenu_items(self):
menu_items = super().get_submenu_items()
menu_items.append(
MenuItem('Calendar', reverse('calendar'), icon_name='date'),
)
return menu_items
modeladmin_register(CalendarGroup)
```

Wyświetl plik

@ -23,7 +23,7 @@ depth: 1
### Documentation
* ...
* Document how to add non-ModelAdmin views to a `ModelAdminGroup` (Onno Timmerman)
### Maintenance