Skip to content
Snippets Groups Projects
models.py 1.2 KiB
Newer Older
  • Learn to ignore specific revisions
  • from django.db import models
    
    from modelcluster.fields import ParentalKey
    
    from wagtail.core.fields import RichTextField
    from wagtail.admin.edit_handlers import (
        FieldPanel, FieldRowPanel, MultiFieldPanel, InlinePanel
    )
    from wagtail.contrib.forms.models import AbstractEmailForm, AbstractFormField
    from wagtail.search import index
    
    from opentech.public.utils.models import BasePage
    
    
    class FormField(AbstractFormField):
        page = ParentalKey('FormPage', on_delete=models.CASCADE, related_name='form_fields')
    
    
    class FormPage(AbstractEmailForm, BasePage):
        subpage_types = []
    
        intro = RichTextField(blank=True)
        thank_you_text = RichTextField(blank=True)
    
        search_fields = BasePage.search_fields + [
            index.SearchField('intro'),
        ]
    
        content_panels = AbstractEmailForm.content_panels + [
            FieldPanel('intro', classname="full"),
            InlinePanel('form_fields', label="Form fields"),
            FieldPanel('thank_you_text', classname="full"),
            MultiFieldPanel([
                FieldRowPanel([
                    FieldPanel('from_address', classname="col6"),
                    FieldPanel('to_address', classname="col6"),
                ]),
                FieldPanel('subject'),
            ], "Email"),
        ]