wagtail_hooks.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. from wagtail import hooks
  2. from wagtail.contrib.modeladmin.options import (
  3. ModelAdmin,
  4. ModelAdminGroup,
  5. modeladmin_register,
  6. )
  7. from bakerydemo.base.models import FooterText, Person
  8. from bakerydemo.breads.models import BreadIngredient, BreadType, Country
  9. """
  10. N.B. To see what icons are available for use in Wagtail menus and StreamField block types,
  11. enable the styleguide in settings:
  12. INSTALLED_APPS = (
  13. ...
  14. 'wagtail.contrib.styleguide',
  15. ...
  16. )
  17. or see https://thegrouchy.dev/general/2015/12/06/wagtail-streamfield-icons.html
  18. This demo project also includes the wagtail-font-awesome-svg package, allowing further icons to be
  19. installed as detailed here: https://github.com/allcaps/wagtail-font-awesome-svg#usage
  20. """
  21. @hooks.register("register_icons")
  22. def register_icons(icons):
  23. return icons + [
  24. "wagtailfontawesomesvg/solid/suitcase.svg",
  25. "wagtailfontawesomesvg/solid/utensils.svg",
  26. ]
  27. class BreadIngredientAdmin(ModelAdmin):
  28. # These stub classes allow us to put various models into the custom "Wagtail Bakery" menu item
  29. # rather than under the default Snippets section.
  30. model = BreadIngredient
  31. search_fields = ("name",)
  32. class BreadTypeAdmin(ModelAdmin):
  33. model = BreadType
  34. search_fields = ("title",)
  35. class BreadCountryAdmin(ModelAdmin):
  36. model = Country
  37. search_fields = ("title",)
  38. class BreadModelAdminGroup(ModelAdminGroup):
  39. menu_label = "Bread Categories"
  40. menu_icon = "suitcase" # change as required
  41. menu_order = 200 # will put in 3rd place (000 being 1st, 100 2nd)
  42. items = (BreadIngredientAdmin, BreadTypeAdmin, BreadCountryAdmin)
  43. class PersonModelAdmin(ModelAdmin):
  44. model = Person
  45. menu_label = "People" # ditch this to use verbose_name_plural from model
  46. menu_icon = "group" # change as required
  47. list_display = ("first_name", "last_name", "job_title", "thumb_image")
  48. list_filter = ("job_title",)
  49. search_fields = ("first_name", "last_name", "job_title")
  50. inspect_view_enabled = True
  51. class FooterTextAdmin(ModelAdmin):
  52. model = FooterText
  53. search_fields = ("body",)
  54. class BakeryModelAdminGroup(ModelAdminGroup):
  55. menu_label = "Bakery Misc"
  56. menu_icon = "utensils" # change as required
  57. menu_order = 300 # will put in 4th place (000 being 1st, 100 2nd)
  58. items = (PersonModelAdmin, FooterTextAdmin)
  59. # When using a ModelAdminGroup class to group several ModelAdmin classes together,
  60. # you only need to register the ModelAdminGroup class with Wagtail:
  61. modeladmin_register(BreadModelAdminGroup)
  62. modeladmin_register(BakeryModelAdminGroup)