forked from external/museum

weicd
2023-02-27 e6a1fb2c444f410ac967b98bd6402e3c6cb1c97d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from wagtail.contrib.modeladmin.options import (
    ModelAdmin, modeladmin_register, ModelAdminGroup)
from wagtail.core import hooks
 
from .models import Book, Author, Genre
 
 
@hooks.register('construct_main_menu')
def hide_images_menu_item(request, menu_items):
    menu_items[:] = [item for item in menu_items if item.name != 'help']
 
 
# @hooks.register('construct_settings_menu')
# def hide_user_menu_item(request, menu_items):
#     menu_items[:] = [item for item in menu_items if item.name != 'user']
 
 
class BookAdmin(ModelAdmin):
    model = Book
    menu_label = 'Book'  # ditch this to use verbose_name_plural from model
    menu_icon = 'pilcrow'  # change as required
    # menu_order = 3000  # will put in 3rd place (000 being 1st, 100 2nd)
    # add_to_settings_menu = True  # or True to add your model to the Settings sub-menu
    # exclude_from_explorer = True  # or True to exclude pages of this type from Wagtail's explorer view
    list_display = ('title', 'author', 'cover_photo')
    list_filter = ('author',)
    search_fields = ('title', 'author')
 
 
class AuthorAdmin(ModelAdmin):
    model = Author
    menu_label = 'Author'  # ditch this to use verbose_name_plural from model
    menu_icon = 'user'  # change as required
    list_display = ('first_name', 'last_name')
    list_filter = ('first_name', 'last_name')
    search_fields = ('first_name', 'last_name')
 
 
class GenreAdmin(ModelAdmin):
    model = Genre
    menu_label = 'Genre'  # ditch this to use verbose_name_plural from model
    menu_icon = 'group'  # change as required
    list_display = ('name',)
    list_filter = ('name',)
    search_fields = ('name',)
 
 
class LibraryGroup(ModelAdminGroup):
    menu_label = 'Library'
    menu_icon = 'folder-open-inverse'  # change as required
    menu_order = 2000  # will put in 3rd place (000 being 1st, 100 2nd)
    items = (BookAdmin, AuthorAdmin, GenreAdmin)
 
# Now you just need to register your customised ModelAdmin class with Wagtail
# modeladmin_register(LibraryGroup)
# modeladmin_register(BookAdmin)
# modeladmin_register(AuthorAdmin)
# modeladmin_register(GenreAdmin)