wagtail_hooks.py 2.2 KB

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