The base models provide the foundational page types and snippets used throughout the Wagtail Bakery Demo. This includes the Person snippet, HomePage with featured sections, form functionality, gallery pages, and site settings.
A snippet model to store Person objects with full workflow and revision support.
Full Class Definition
class Person( WorkflowMixin, DraftStateMixin, LockableMixin, RevisionMixin, PreviewableMixin, index.Indexed, ClusterableModel,): """ A Django model to store Person objects. It is registered using `register_snippet` as a function in wagtail_hooks.py to allow it to have a menu item within a custom menu item group. `Person` uses the `ClusterableModel`, which allows the relationship with another model to be stored locally to the 'parent' model (e.g. a PageModel) until the parent is explicitly saved. This allows the editor to use the 'Preview' button, to preview the content, without saving the relationships to the database. https://github.com/wagtail/django-modelcluster """ first_name = models.CharField("First name", max_length=254) last_name = models.CharField("Last name", max_length=254) job_title = models.CharField("Job title", max_length=254) image = models.ForeignKey( "wagtailimages.Image", null=True, blank=True, on_delete=models.SET_NULL, related_name="+", ) workflow_states = GenericRelation( "wagtailcore.WorkflowState", content_type_field="base_content_type", object_id_field="object_id", related_query_name="person", for_concrete_model=False, ) revisions = GenericRelation( "wagtailcore.Revision", content_type_field="base_content_type", object_id_field="object_id", related_query_name="person", for_concrete_model=False, )
@propertydef thumb_image(self): # Returns an empty string if there is no profile pic or the rendition # file can't be found. try: return self.image.get_rendition("fill-50x50").img_tag() except: return ""
Returns a 50x50 thumbnail image tag, or empty string if image unavailable.
A generic content page for general-purpose content.
Full Class Definition
class StandardPage(Page): """ A generic content page. On this demo site we use it for an about page but it could be used for any type of page content that only needs a title, image, introduction and body field """ introduction = models.TextField(help_text="Text to describe the page", blank=True) image = models.ForeignKey( "wagtailimages.Image", null=True, blank=True, on_delete=models.SET_NULL, related_name="+", help_text="Landscape mode only; horizontal width between 1000px and 3000px.", ) body = StreamField( BaseStreamBlock(), verbose_name="Page body", blank=True, use_json_field=True )
Page to display images from a selected Wagtail Collection.
Full Class Definition
class GalleryPage(Page): """ This is a page to list locations from the selected Collection. We use a Q object to list any Collection created (/admin/collections/) even if they contain no items. In this demo we use it for a GalleryPage, and is intended to show the extensibility of this aspect of Wagtail """ introduction = models.TextField(help_text="Text to describe the page", blank=True) image = models.ForeignKey( "wagtailimages.Image", null=True, blank=True, on_delete=models.SET_NULL, related_name="+", help_text="Landscape mode only; horizontal width between 1000px and 3000px.", ) body = StreamField( BaseStreamBlock(), verbose_name="Page body", blank=True, use_json_field=True ) collection = models.ForeignKey( Collection, limit_choices_to=~models.Q(name__in=["Root"]), null=True, blank=True, on_delete=models.SET_NULL, help_text="Select the image collection for this gallery.", )
class FooterText( DraftStateMixin, RevisionMixin, PreviewableMixin, TranslatableMixin, models.Model,): """ This provides editable text for the site footer. Again it is registered using `register_snippet` as a function in wagtail_hooks.py to be grouped together with the Person model inside the same main menu item. It is made accessible on the template via a template tag defined in base/templatetags/ navigation_tags.py """ body = RichTextField() revisions = GenericRelation( "wagtailcore.Revision", content_type_field="base_content_type", object_id_field="object_id", related_query_name="footer_text", for_concrete_model=False, )
@register_setting(icon="site")class SiteSettings(BaseSiteSetting): title_suffix = models.CharField( verbose_name="Title suffix", max_length=255, help_text="The suffix for the title meta tag e.g. ' | The Wagtail Bakery'", default="The Wagtail Bakery", )