wagtail_hooks.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. panels = [
  35. FieldPanel("title"),
  36. ]
  37. # We want to group several snippets together in the admin menu.
  38. # This is done by defining a SnippetViewSetGroup class that contains a list of
  39. # SnippetViewSet classes.
  40. # When using a SnippetViewSetGroup class to group several SnippetViewSet classes together,
  41. # you only need to register the SnippetViewSetGroup class with Wagtail.
  42. # No need to register the individual SnippetViewSet classes.
  43. #
  44. # See the documentation for SnippetViewSet for more details.
  45. # https://docs.wagtail.org/en/stable/reference/viewsets.html#snippetviewsetgroup
  46. class BreadMenuGroup(SnippetViewSetGroup):
  47. menu_label = "Bread Categories"
  48. menu_icon = "suitcase" # change as required
  49. menu_order = 200 # will put in 3rd place (000 being 1st, 100 2nd)
  50. items = (
  51. BreadIngredientSnippetViewSet,
  52. BreadTypeSnippetViewSet,
  53. CountryModelViewSet,
  54. )
  55. register_snippet(BreadMenuGroup)