From 7368667f96c1b2998fd39b9dec2d1376ff42aa53 Mon Sep 17 00:00:00 2001 From: Sage Abdullah Date: Tue, 23 Apr 2024 10:30:25 +0700 Subject: [PATCH] Register Country model with a ModelViewSet This serves as an example of how ModelViewSet can be mixed with snippets in a SnippetViewSetGroup --- bakerydemo/breads/wagtail_hooks.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bakerydemo/breads/wagtail_hooks.py b/bakerydemo/breads/wagtail_hooks.py index 3ff6bc3..6575b06 100644 --- a/bakerydemo/breads/wagtail_hooks.py +++ b/bakerydemo/breads/wagtail_hooks.py @@ -1,4 +1,6 @@ from wagtail.admin.filters import WagtailFilterSet +from wagtail.admin.panels import FieldPanel +from wagtail.admin.viewsets.model import ModelViewSet from wagtail.snippets.models import register_snippet from wagtail.snippets.views.snippets import SnippetViewSet, SnippetViewSetGroup @@ -35,10 +37,15 @@ class BreadTypeSnippetViewSet(SnippetViewSet): filterset_class = BreadTypeFilterSet -class CountrySnippetViewSet(SnippetViewSet): +class CountryModelViewSet(ModelViewSet): model = Country ordering = ("title",) search_fields = ("title",) + icon = "globe" + + panels = [ + FieldPanel("title"), + ] # We want to group several snippets together in the admin menu. @@ -57,7 +64,7 @@ class BreadMenuGroup(SnippetViewSetGroup): items = ( BreadIngredientSnippetViewSet, BreadTypeSnippetViewSet, - CountrySnippetViewSet, + CountryModelViewSet, )