Skip to content

Commit 3295796

Browse files
laymonagethibaudcolas
authored andcommitted
Add api_fields to models
1 parent f0e91df commit 3295796

File tree

5 files changed

+149
-3
lines changed

5 files changed

+149
-3
lines changed

bakerydemo/base/models.py

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
from wagtail.admin.panels import (
88
FieldPanel,
99
FieldRowPanel,
10+
HelpPanel,
1011
InlinePanel,
1112
MultiFieldPanel,
1213
PublishingPanel,
1314
)
15+
from wagtail.api import APIField
1416
from wagtail.contrib.forms.models import AbstractEmailForm, AbstractFormField
1517
from wagtail.contrib.forms.panels import FormSubmissionsPanel
1618
from wagtail.contrib.settings.models import (
@@ -111,6 +113,13 @@ class Person(
111113
index.AutocompleteField("last_name"),
112114
]
113115

116+
api_fields = [
117+
APIField("first_name"),
118+
APIField("last_name"),
119+
APIField("job_title"),
120+
APIField("image"),
121+
]
122+
114123
@property
115124
def thumb_image(self):
116125
# Returns an empty string if there is no profile pic or the rendition
@@ -195,6 +204,10 @@ class FooterText(
195204
PublishingPanel(),
196205
]
197206

207+
api_fields = [
208+
APIField("body"),
209+
]
210+
198211
def __str__(self):
199212
return "Footer text"
200213

@@ -234,6 +247,12 @@ class StandardPage(Page):
234247
FieldPanel("image"),
235248
]
236249

250+
api_fields = [
251+
APIField("introduction"),
252+
APIField("image"),
253+
APIField("body"),
254+
]
255+
237256

238257
class HomePage(Page):
239258
"""
@@ -358,13 +377,15 @@ class HomePage(Page):
358377
],
359378
heading="Hero section",
360379
),
380+
HelpPanel("This is a help panel"),
361381
MultiFieldPanel(
362382
[
363383
FieldPanel("promo_image"),
364384
FieldPanel("promo_title"),
365385
FieldPanel("promo_text"),
366386
],
367387
heading="Promo section",
388+
help_text="This is just a help text",
368389
),
369390
FieldPanel("body"),
370391
MultiFieldPanel(
@@ -392,6 +413,23 @@ class HomePage(Page):
392413
),
393414
]
394415

416+
api_fields = [
417+
APIField("image"),
418+
APIField("hero_text"),
419+
APIField("hero_cta"),
420+
APIField("hero_cta_link"),
421+
APIField("body"),
422+
APIField("promo_image"),
423+
APIField("promo_title"),
424+
APIField("promo_text"),
425+
APIField("featured_section_1_title"),
426+
APIField("featured_section_1"),
427+
APIField("featured_section_2_title"),
428+
APIField("featured_section_2"),
429+
APIField("featured_section_3_title"),
430+
APIField("featured_section_3"),
431+
]
432+
395433
def __str__(self):
396434
return self.title
397435

@@ -411,7 +449,7 @@ class GalleryPage(Page):
411449
blank=True,
412450
on_delete=models.SET_NULL,
413451
related_name="+",
414-
help_text="Landscape mode only; horizontal width between 1000px and " "3000px.",
452+
help_text="Landscape mode only; horizontal width between 1000px and 3000px.",
415453
)
416454
body = StreamField(
417455
BaseStreamBlock(), verbose_name="Page body", blank=True, use_json_field=True
@@ -436,6 +474,13 @@ class GalleryPage(Page):
436474
# array no subpage can be added
437475
subpage_types = []
438476

477+
api_fields = [
478+
APIField("introduction"),
479+
APIField("image"),
480+
APIField("body"),
481+
APIField("collection"),
482+
]
483+
439484

440485
class FormField(AbstractFormField):
441486
"""
@@ -483,6 +528,16 @@ class FormPage(AbstractEmailForm):
483528
),
484529
]
485530

531+
api_fields = [
532+
APIField("form_fields"),
533+
APIField("from_address"),
534+
APIField("to_address"),
535+
APIField("subject"),
536+
APIField("image"),
537+
APIField("body"),
538+
APIField("thank_you_text"),
539+
]
540+
486541

487542
@register_setting(icon="cog")
488543
class GenericSettings(ClusterableModel, BaseGenericSetting):

bakerydemo/blog/models.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from modelcluster.fields import ParentalKey
66
from taggit.models import Tag, TaggedItemBase
77
from wagtail.admin.panels import FieldPanel, MultipleChooserPanel
8+
from wagtail.api import APIField
89
from wagtail.contrib.routable_page.models import RoutablePageMixin, route
910
from wagtail.fields import StreamField
1011
from wagtail.models import Orderable, Page
@@ -30,6 +31,11 @@ class BlogPersonRelationship(Orderable, models.Model):
3031
)
3132
panels = [FieldPanel("person")]
3233

34+
api_fields = [
35+
APIField("page"),
36+
APIField("person"),
37+
]
38+
3339

3440
class BlogPageTag(TaggedItemBase):
3541
"""
@@ -89,6 +95,16 @@ class BlogPage(Page):
8995
index.SearchField("body"),
9096
]
9197

98+
api_fields = [
99+
APIField("introduction"),
100+
APIField("image"),
101+
APIField("body"),
102+
APIField("subtitle"),
103+
APIField("tags"),
104+
APIField("date_published"),
105+
APIField("blog_person_relationship"),
106+
]
107+
92108
def authors(self):
93109
"""
94110
Returns the BlogPage's related people. Again note that we are using
@@ -151,6 +167,11 @@ class BlogIndexPage(RoutablePageMixin, Page):
151167
FieldPanel("image"),
152168
]
153169

170+
api_fields = [
171+
APIField("introduction"),
172+
APIField("image"),
173+
]
174+
154175
# Specifies that only BlogPage objects can live under this index page
155176
subpage_types = ["BlogPage"]
156177

@@ -176,7 +197,6 @@ def get_context(self, request):
176197
@route(r"^tags/$", name="tag_archive")
177198
@route(r"^tags/([\w-]+)/$", name="tag_archive")
178199
def tag_archive(self, request, tag=None):
179-
180200
try:
181201
tag = Tag.objects.get(slug=tag)
182202
except Tag.DoesNotExist:

bakerydemo/breads/models.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from django.db import models
55
from modelcluster.fields import ParentalManyToManyField
66
from wagtail.admin.panels import FieldPanel, MultiFieldPanel
7+
from wagtail.api import APIField
78
from wagtail.fields import StreamField
89
from wagtail.models import DraftStateMixin, Page, RevisionMixin
910
from wagtail.search import index
@@ -24,6 +25,10 @@ class in wagtail_hooks.py. This allows us to customize the admin interface for t
2425

2526
title = models.CharField(max_length=100)
2627

28+
api_fields = [
29+
APIField("title"),
30+
]
31+
2732
def __str__(self):
2833
return self.title
2934

@@ -56,6 +61,10 @@ class in wagtail_hooks.py. This allows us to customize the admin interface for t
5661
FieldPanel("name"),
5762
]
5863

64+
api_fields = [
65+
APIField("name"),
66+
]
67+
5968
def __str__(self):
6069
return self.name
6170

@@ -89,6 +98,10 @@ class in wagtail_hooks.py. This allows us to customize the admin interface for t
8998
FieldPanel("title"),
9099
]
91100

101+
api_fields = [
102+
APIField("title"),
103+
]
104+
92105
def __str__(self):
93106
return self.title
94107

@@ -159,6 +172,15 @@ class BreadPage(Page):
159172

160173
parent_page_types = ["BreadsIndexPage"]
161174

175+
api_fields = [
176+
APIField("introduction"),
177+
APIField("image"),
178+
APIField("body"),
179+
APIField("origin"),
180+
APIField("bread_type"),
181+
APIField("ingredients"),
182+
]
183+
162184

163185
class BreadsIndexPage(Page):
164186
"""
@@ -176,7 +198,7 @@ class BreadsIndexPage(Page):
176198
blank=True,
177199
on_delete=models.SET_NULL,
178200
related_name="+",
179-
help_text="Landscape mode only; horizontal width between 1000px and " "3000px.",
201+
help_text="Landscape mode only; horizontal width between 1000px and 3000px.",
180202
)
181203

182204
content_panels = Page.content_panels + [
@@ -187,6 +209,11 @@ class BreadsIndexPage(Page):
187209
# Can only have BreadPage children
188210
subpage_types = ["BreadPage"]
189211

212+
api_fields = [
213+
APIField("introduction"),
214+
APIField("image"),
215+
]
216+
190217
# Returns a queryset of BreadPage objects that are live, that are direct
191218
# descendants of this index page with most recent first
192219
def get_breads(self):

bakerydemo/locations/models.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from django.db import models
66
from modelcluster.fields import ParentalKey
77
from wagtail.admin.panels import FieldPanel, InlinePanel
8+
from wagtail.api import APIField
89
from wagtail.fields import StreamField
910
from wagtail.models import Orderable, Page
1011
from wagtail.search import index
@@ -25,6 +26,14 @@ class OperatingHours(models.Model):
2526
"Closed?", blank=True, help_text="Tick if location is closed on this day"
2627
)
2728

29+
api_fields = [
30+
APIField("day"),
31+
APIField("get_day_display"),
32+
APIField("opening_time"),
33+
APIField("closing_time"),
34+
APIField("closed"),
35+
]
36+
2837
panels = [
2938
FieldPanel("day"),
3039
FieldPanel("opening_time"),
@@ -101,6 +110,11 @@ def get_context(self, request):
101110
FieldPanel("image"),
102111
]
103112

113+
api_fields = [
114+
APIField("introduction"),
115+
APIField("image"),
116+
]
117+
104118

105119
class LocationPage(Page):
106120
"""
@@ -150,6 +164,16 @@ class LocationPage(Page):
150164
InlinePanel("hours_of_operation", heading="Hours of Operation", label="Slot"),
151165
]
152166

167+
api_fields = [
168+
APIField("introduction"),
169+
APIField("image"),
170+
APIField("body"),
171+
APIField("address"),
172+
APIField("lat_long"),
173+
APIField("is_open"),
174+
APIField("hours_of_operation"),
175+
]
176+
153177
def __str__(self):
154178
return self.title
155179

bakerydemo/recipes/models.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
MultiFieldPanel,
77
MultipleChooserPanel,
88
)
9+
from wagtail.api import APIField
910
from wagtail.fields import RichTextField, StreamField
1011
from wagtail.models import Orderable, Page
1112
from wagtail.search import index
@@ -36,6 +37,11 @@ class RecipePersonRelationship(Orderable, models.Model):
3637
)
3738
panels = [FieldPanel("person")]
3839

40+
api_fields = [
41+
APIField("page"),
42+
APIField("person"),
43+
]
44+
3945

4046
class RecipePage(Page):
4147
"""
@@ -107,6 +113,16 @@ class RecipePage(Page):
107113
index.SearchField("body"),
108114
]
109115

116+
api_fields = [
117+
APIField("date_published"),
118+
APIField("subtitle"),
119+
APIField("introduction"),
120+
APIField("backstory"),
121+
APIField("recipe_headline"),
122+
APIField("body"),
123+
APIField("recipe_person_relationship"),
124+
]
125+
110126
def authors(self):
111127
"""
112128
Returns the RecipePage's related people. Again note that we are using
@@ -144,6 +160,10 @@ class RecipeIndexPage(Page):
144160
FieldPanel("introduction"),
145161
]
146162

163+
api_fields = [
164+
APIField("introduction"),
165+
]
166+
147167
# Specifies that only RecipePage objects can live under this index page
148168
subpage_types = ["RecipePage"]
149169

0 commit comments

Comments
 (0)