Browse Source

Add api_fields to models

Sage Abdullah 2 months ago
parent
commit
8053c581b4

+ 56 - 1
bakerydemo/base/models.py

@@ -7,10 +7,12 @@ from modelcluster.models import ClusterableModel
 from wagtail.admin.panels import (
 from wagtail.admin.panels import (
     FieldPanel,
     FieldPanel,
     FieldRowPanel,
     FieldRowPanel,
+    HelpPanel,
     InlinePanel,
     InlinePanel,
     MultiFieldPanel,
     MultiFieldPanel,
     PublishingPanel,
     PublishingPanel,
 )
 )
+from wagtail.api import APIField
 from wagtail.contrib.forms.models import AbstractEmailForm, AbstractFormField
 from wagtail.contrib.forms.models import AbstractEmailForm, AbstractFormField
 from wagtail.contrib.forms.panels import FormSubmissionsPanel
 from wagtail.contrib.forms.panels import FormSubmissionsPanel
 from wagtail.contrib.settings.models import (
 from wagtail.contrib.settings.models import (
@@ -111,6 +113,13 @@ class Person(
         index.AutocompleteField("last_name"),
         index.AutocompleteField("last_name"),
     ]
     ]
 
 
+    api_fields = [
+        APIField("first_name"),
+        APIField("last_name"),
+        APIField("job_title"),
+        APIField("image"),
+    ]
+
     @property
     @property
     def thumb_image(self):
     def thumb_image(self):
         # Returns an empty string if there is no profile pic or the rendition
         # Returns an empty string if there is no profile pic or the rendition
@@ -195,6 +204,10 @@ class FooterText(
         PublishingPanel(),
         PublishingPanel(),
     ]
     ]
 
 
+    api_fields = [
+        APIField("body"),
+    ]
+
     def __str__(self):
     def __str__(self):
         return "Footer text"
         return "Footer text"
 
 
@@ -234,6 +247,12 @@ class StandardPage(Page):
         FieldPanel("image"),
         FieldPanel("image"),
     ]
     ]
 
 
+    api_fields = [
+        APIField("introduction"),
+        APIField("image"),
+        APIField("body"),
+    ]
+
 
 
 class HomePage(Page):
 class HomePage(Page):
     """
     """
@@ -358,6 +377,7 @@ class HomePage(Page):
             ],
             ],
             heading="Hero section",
             heading="Hero section",
         ),
         ),
+        HelpPanel("This is a help panel"),
         MultiFieldPanel(
         MultiFieldPanel(
             [
             [
                 FieldPanel("promo_image"),
                 FieldPanel("promo_image"),
@@ -365,6 +385,7 @@ class HomePage(Page):
                 FieldPanel("promo_text"),
                 FieldPanel("promo_text"),
             ],
             ],
             heading="Promo section",
             heading="Promo section",
+            help_text="This is just a help text",
         ),
         ),
         FieldPanel("body"),
         FieldPanel("body"),
         MultiFieldPanel(
         MultiFieldPanel(
@@ -392,6 +413,23 @@ class HomePage(Page):
         ),
         ),
     ]
     ]
 
 
+    api_fields = [
+        APIField("image"),
+        APIField("hero_text"),
+        APIField("hero_cta"),
+        APIField("hero_cta_link"),
+        APIField("body"),
+        APIField("promo_image"),
+        APIField("promo_title"),
+        APIField("promo_text"),
+        APIField("featured_section_1_title"),
+        APIField("featured_section_1"),
+        APIField("featured_section_2_title"),
+        APIField("featured_section_2"),
+        APIField("featured_section_3_title"),
+        APIField("featured_section_3"),
+    ]
+
     def __str__(self):
     def __str__(self):
         return self.title
         return self.title
 
 
@@ -411,7 +449,7 @@ class GalleryPage(Page):
         blank=True,
         blank=True,
         on_delete=models.SET_NULL,
         on_delete=models.SET_NULL,
         related_name="+",
         related_name="+",
-        help_text="Landscape mode only; horizontal width between 1000px and " "3000px.",
+        help_text="Landscape mode only; horizontal width between 1000px and 3000px.",
     )
     )
     body = StreamField(
     body = StreamField(
         BaseStreamBlock(), verbose_name="Page body", blank=True, use_json_field=True
         BaseStreamBlock(), verbose_name="Page body", blank=True, use_json_field=True
@@ -436,6 +474,13 @@ class GalleryPage(Page):
     # array no subpage can be added
     # array no subpage can be added
     subpage_types = []
     subpage_types = []
 
 
+    api_fields = [
+        APIField("introduction"),
+        APIField("image"),
+        APIField("body"),
+        APIField("collection"),
+    ]
+
 
 
 class FormField(AbstractFormField):
 class FormField(AbstractFormField):
     """
     """
@@ -483,6 +528,16 @@ class FormPage(AbstractEmailForm):
         ),
         ),
     ]
     ]
 
 
+    api_fields = [
+        APIField("form_fields"),
+        APIField("from_address"),
+        APIField("to_address"),
+        APIField("subject"),
+        APIField("image"),
+        APIField("body"),
+        APIField("thank_you_text"),
+    ]
+
 
 
 @register_setting(icon="cog")
 @register_setting(icon="cog")
 class GenericSettings(ClusterableModel, BaseGenericSetting):
 class GenericSettings(ClusterableModel, BaseGenericSetting):

+ 21 - 1
bakerydemo/blog/models.py

@@ -5,6 +5,7 @@ from modelcluster.contrib.taggit import ClusterTaggableManager
 from modelcluster.fields import ParentalKey
 from modelcluster.fields import ParentalKey
 from taggit.models import Tag, TaggedItemBase
 from taggit.models import Tag, TaggedItemBase
 from wagtail.admin.panels import FieldPanel, MultipleChooserPanel
 from wagtail.admin.panels import FieldPanel, MultipleChooserPanel
+from wagtail.api import APIField
 from wagtail.contrib.routable_page.models import RoutablePageMixin, route
 from wagtail.contrib.routable_page.models import RoutablePageMixin, route
 from wagtail.fields import StreamField
 from wagtail.fields import StreamField
 from wagtail.models import Orderable, Page
 from wagtail.models import Orderable, Page
@@ -30,6 +31,11 @@ class BlogPersonRelationship(Orderable, models.Model):
     )
     )
     panels = [FieldPanel("person")]
     panels = [FieldPanel("person")]
 
 
+    api_fields = [
+        APIField("page"),
+        APIField("person"),
+    ]
+
 
 
 class BlogPageTag(TaggedItemBase):
 class BlogPageTag(TaggedItemBase):
     """
     """
@@ -89,6 +95,16 @@ class BlogPage(Page):
         index.SearchField("body"),
         index.SearchField("body"),
     ]
     ]
 
 
+    api_fields = [
+        APIField("introduction"),
+        APIField("image"),
+        APIField("body"),
+        APIField("subtitle"),
+        APIField("tags"),
+        APIField("date_published"),
+        APIField("blog_person_relationship"),
+    ]
+
     def authors(self):
     def authors(self):
         """
         """
         Returns the BlogPage's related people. Again note that we are using
         Returns the BlogPage's related people. Again note that we are using
@@ -151,6 +167,11 @@ class BlogIndexPage(RoutablePageMixin, Page):
         FieldPanel("image"),
         FieldPanel("image"),
     ]
     ]
 
 
+    api_fields = [
+        APIField("introduction"),
+        APIField("image"),
+    ]
+
     # Specifies that only BlogPage objects can live under this index page
     # Specifies that only BlogPage objects can live under this index page
     subpage_types = ["BlogPage"]
     subpage_types = ["BlogPage"]
 
 
@@ -176,7 +197,6 @@ class BlogIndexPage(RoutablePageMixin, Page):
     @route(r"^tags/$", name="tag_archive")
     @route(r"^tags/$", name="tag_archive")
     @route(r"^tags/([\w-]+)/$", name="tag_archive")
     @route(r"^tags/([\w-]+)/$", name="tag_archive")
     def tag_archive(self, request, tag=None):
     def tag_archive(self, request, tag=None):
-
         try:
         try:
             tag = Tag.objects.get(slug=tag)
             tag = Tag.objects.get(slug=tag)
         except Tag.DoesNotExist:
         except Tag.DoesNotExist:

+ 28 - 1
bakerydemo/breads/models.py

@@ -4,6 +4,7 @@ from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
 from django.db import models
 from django.db import models
 from modelcluster.fields import ParentalManyToManyField
 from modelcluster.fields import ParentalManyToManyField
 from wagtail.admin.panels import FieldPanel, MultiFieldPanel
 from wagtail.admin.panels import FieldPanel, MultiFieldPanel
+from wagtail.api import APIField
 from wagtail.fields import StreamField
 from wagtail.fields import StreamField
 from wagtail.models import DraftStateMixin, Page, RevisionMixin
 from wagtail.models import DraftStateMixin, Page, RevisionMixin
 from wagtail.search import index
 from wagtail.search import index
@@ -24,6 +25,10 @@ class Country(models.Model):
 
 
     title = models.CharField(max_length=100)
     title = models.CharField(max_length=100)
 
 
+    api_fields = [
+        APIField("title"),
+    ]
+
     def __str__(self):
     def __str__(self):
         return self.title
         return self.title
 
 
@@ -56,6 +61,10 @@ class BreadIngredient(DraftStateMixin, RevisionMixin, models.Model):
         FieldPanel("name"),
         FieldPanel("name"),
     ]
     ]
 
 
+    api_fields = [
+        APIField("name"),
+    ]
+
     def __str__(self):
     def __str__(self):
         return self.name
         return self.name
 
 
@@ -89,6 +98,10 @@ class BreadType(RevisionMixin, models.Model):
         FieldPanel("title"),
         FieldPanel("title"),
     ]
     ]
 
 
+    api_fields = [
+        APIField("title"),
+    ]
+
     def __str__(self):
     def __str__(self):
         return self.title
         return self.title
 
 
@@ -159,6 +172,15 @@ class BreadPage(Page):
 
 
     parent_page_types = ["BreadsIndexPage"]
     parent_page_types = ["BreadsIndexPage"]
 
 
+    api_fields = [
+        APIField("introduction"),
+        APIField("image"),
+        APIField("body"),
+        APIField("origin"),
+        APIField("bread_type"),
+        APIField("ingredients"),
+    ]
+
 
 
 class BreadsIndexPage(Page):
 class BreadsIndexPage(Page):
     """
     """
@@ -176,7 +198,7 @@ class BreadsIndexPage(Page):
         blank=True,
         blank=True,
         on_delete=models.SET_NULL,
         on_delete=models.SET_NULL,
         related_name="+",
         related_name="+",
-        help_text="Landscape mode only; horizontal width between 1000px and " "3000px.",
+        help_text="Landscape mode only; horizontal width between 1000px and 3000px.",
     )
     )
 
 
     content_panels = Page.content_panels + [
     content_panels = Page.content_panels + [
@@ -187,6 +209,11 @@ class BreadsIndexPage(Page):
     # Can only have BreadPage children
     # Can only have BreadPage children
     subpage_types = ["BreadPage"]
     subpage_types = ["BreadPage"]
 
 
+    api_fields = [
+        APIField("introduction"),
+        APIField("image"),
+    ]
+
     # Returns a queryset of BreadPage objects that are live, that are direct
     # Returns a queryset of BreadPage objects that are live, that are direct
     # descendants of this index page with most recent first
     # descendants of this index page with most recent first
     def get_breads(self):
     def get_breads(self):

+ 24 - 0
bakerydemo/locations/models.py

@@ -5,6 +5,7 @@ from django.core.validators import RegexValidator
 from django.db import models
 from django.db import models
 from modelcluster.fields import ParentalKey
 from modelcluster.fields import ParentalKey
 from wagtail.admin.panels import FieldPanel, InlinePanel
 from wagtail.admin.panels import FieldPanel, InlinePanel
+from wagtail.api import APIField
 from wagtail.fields import StreamField
 from wagtail.fields import StreamField
 from wagtail.models import Orderable, Page
 from wagtail.models import Orderable, Page
 from wagtail.search import index
 from wagtail.search import index
@@ -25,6 +26,14 @@ class OperatingHours(models.Model):
         "Closed?", blank=True, help_text="Tick if location is closed on this day"
         "Closed?", blank=True, help_text="Tick if location is closed on this day"
     )
     )
 
 
+    api_fields = [
+        APIField("day"),
+        APIField("get_day_display"),
+        APIField("opening_time"),
+        APIField("closing_time"),
+        APIField("closed"),
+    ]
+
     panels = [
     panels = [
         FieldPanel("day"),
         FieldPanel("day"),
         FieldPanel("opening_time"),
         FieldPanel("opening_time"),
@@ -101,6 +110,11 @@ class LocationsIndexPage(Page):
         FieldPanel("image"),
         FieldPanel("image"),
     ]
     ]
 
 
+    api_fields = [
+        APIField("introduction"),
+        APIField("image"),
+    ]
+
 
 
 class LocationPage(Page):
 class LocationPage(Page):
     """
     """
@@ -150,6 +164,16 @@ class LocationPage(Page):
         InlinePanel("hours_of_operation", heading="Hours of Operation", label="Slot"),
         InlinePanel("hours_of_operation", heading="Hours of Operation", label="Slot"),
     ]
     ]
 
 
+    api_fields = [
+        APIField("introduction"),
+        APIField("image"),
+        APIField("body"),
+        APIField("address"),
+        APIField("lat_long"),
+        APIField("is_open"),
+        APIField("hours_of_operation"),
+    ]
+
     def __str__(self):
     def __str__(self):
         return self.title
         return self.title
 
 

+ 21 - 1
bakerydemo/recipes/models.py

@@ -6,6 +6,7 @@ from wagtail.admin.panels import (
     MultiFieldPanel,
     MultiFieldPanel,
     MultipleChooserPanel,
     MultipleChooserPanel,
 )
 )
+from wagtail.api import APIField
 from wagtail.fields import RichTextField, StreamField
 from wagtail.fields import RichTextField, StreamField
 from wagtail.models import Orderable, Page
 from wagtail.models import Orderable, Page
 from wagtail.search import index
 from wagtail.search import index
@@ -36,6 +37,11 @@ class RecipePersonRelationship(Orderable, models.Model):
     )
     )
     panels = [FieldPanel("person")]
     panels = [FieldPanel("person")]
 
 
+    api_fields = [
+        APIField("page"),
+        APIField("person"),
+    ]
+
 
 
 class RecipePage(Page):
 class RecipePage(Page):
     """
     """
@@ -69,7 +75,7 @@ class RecipePage(Page):
         RecipeStreamBlock(),
         RecipeStreamBlock(),
         blank=True,
         blank=True,
         use_json_field=True,
         use_json_field=True,
-        help_text="The recipes step-by-step instructions and any other relevant information.",
+        help_text="The recipe's step-by-step instructions and any other relevant information.",
     )
     )
 
 
     content_panels = Page.content_panels + [
     content_panels = Page.content_panels + [
@@ -107,6 +113,16 @@ class RecipePage(Page):
         index.SearchField("body"),
         index.SearchField("body"),
     ]
     ]
 
 
+    api_fields = [
+        APIField("date_published"),
+        APIField("subtitle"),
+        APIField("introduction"),
+        APIField("backstory"),
+        APIField("recipe_headline"),
+        APIField("body"),
+        APIField("recipe_person_relationship"),
+    ]
+
     def authors(self):
     def authors(self):
         """
         """
         Returns the RecipePage's related people. Again note that we are using
         Returns the RecipePage's related people. Again note that we are using
@@ -144,6 +160,10 @@ class RecipeIndexPage(Page):
         FieldPanel("introduction"),
         FieldPanel("introduction"),
     ]
     ]
 
 
+    api_fields = [
+        APIField("introduction"),
+    ]
+
     # Specifies that only RecipePage objects can live under this index page
     # Specifies that only RecipePage objects can live under this index page
     subpage_types = ["RecipePage"]
     subpage_types = ["RecipePage"]