wagtail_hooks.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from wagtail.snippets.models import register_snippet
  2. from wagtail.snippets.views.snippets import SnippetViewSet, SnippetViewSetGroup
  3. from bakerydemo.breads.models import BreadIngredient, BreadType, Country
  4. class BreadIngredientSnippetViewSet(SnippetViewSet):
  5. model = BreadIngredient
  6. ordering = ("name",)
  7. search_fields = ("name",)
  8. inspect_view_enabled = True
  9. class BreadTypeSnippetViewSet(SnippetViewSet):
  10. model = BreadType
  11. ordering = ("title",)
  12. search_fields = ("title",)
  13. class CountrySnippetViewSet(SnippetViewSet):
  14. model = Country
  15. ordering = ("title",)
  16. search_fields = ("title",)
  17. # We want to group several snippets together in the admin menu.
  18. # This is done by defining a SnippetViewSetGroup class that contains a list of
  19. # SnippetViewSet classes.
  20. # When using a SnippetViewSetGroup class to group several SnippetViewSet classes together,
  21. # you only need to register the SnippetViewSetGroup class with Wagtail.
  22. # No need to register the individual SnippetViewSet classes.
  23. #
  24. # See the documentation for SnippetViewSet for more details.
  25. # https://docs.wagtail.org/en/stable/reference/viewsets.html#snippetviewsetgroup
  26. class BreadMenuGroup(SnippetViewSetGroup):
  27. menu_label = "Bread Categories"
  28. menu_icon = "suitcase" # change as required
  29. menu_order = 200 # will put in 3rd place (000 being 1st, 100 2nd)
  30. items = (
  31. BreadIngredientSnippetViewSet,
  32. BreadTypeSnippetViewSet,
  33. CountrySnippetViewSet,
  34. )
  35. register_snippet(BreadMenuGroup)