wagtail_hooks.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. from wagtail.contrib.modeladmin.options import (
  2. ModelAdmin, ModelAdminGroup, modeladmin_register)
  3. from bakerydemo.breads.models import Country, BreadType
  4. from bakerydemo.base.models import People, FooterText
  5. '''
  6. N.B. To see what icons are available for use in Wagtail menus and StreamField block types,
  7. enable the styleguide in settings:
  8. INSTALLED_APPS = (
  9. ...
  10. 'wagtail.contrib.wagtailstyleguide',
  11. ...
  12. )
  13. or see http://kave.github.io/general/2015/12/06/wagtail-streamfield-icons.html
  14. '''
  15. class BreadTypeAdmin(ModelAdmin):
  16. # These stub classes allow us to put various models into the custom "Wagtail Bakery" menu item
  17. # rather than under the default Snippets section.
  18. model = BreadType
  19. class BreadCountryAdmin(ModelAdmin):
  20. model = Country
  21. class BreadModelAdminGroup(ModelAdminGroup):
  22. menu_label = 'Bread Categories'
  23. menu_icon = 'folder-open-inverse' # change as required
  24. menu_order = 200 # will put in 4th place (000 being 1st, 100 2nd)
  25. items = (BreadTypeAdmin, BreadCountryAdmin)
  26. class PeopleModelAdmin(ModelAdmin):
  27. model = People
  28. menu_label = 'People' # ditch this to use verbose_name_plural from model
  29. menu_icon = 'fa-people' # change as required
  30. list_display = ('first_name', 'last_name', 'job_title', 'thumb_image')
  31. class FooterTextAdmin(ModelAdmin):
  32. model = FooterText
  33. class BakeryModelAdminGroup(ModelAdminGroup):
  34. menu_label = 'Wagtail Bakery'
  35. menu_icon = 'folder-open-inverse' # change as required
  36. menu_order = 300 # will put in 3rd place (000 being 1st, 100 2nd)
  37. items = (PeopleModelAdmin, FooterTextAdmin)
  38. # When using a ModelAdminGroup class to group several ModelAdmin classes together,
  39. # you only need to register the ModelAdminGroup class with Wagtail:
  40. modeladmin_register(BreadModelAdminGroup)
  41. modeladmin_register(BakeryModelAdminGroup)