wagtail_hooks.py 2.0 KB

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