wagtail_hooks.py 2.3 KB

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