WIP: modified form models idea
rodzic
f509df6a9d
commit
dc25fa01a7
|
@ -1,4 +1,4 @@
|
||||||
# Generated by Django 4.1.11 on 2023-10-09 19:30
|
# Generated by Django 4.1.11 on 2023-10-10 20:22
|
||||||
|
|
||||||
import django.core.serializers.json
|
import django.core.serializers.json
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
@ -19,19 +19,10 @@ class Migration(migrations.Migration):
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name="CustomEmailForm",
|
name="CustomEmailForm",
|
||||||
fields=[
|
fields=[
|
||||||
(
|
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
|
||||||
"page_ptr",
|
|
||||||
models.OneToOneField(
|
|
||||||
auto_created=True,
|
|
||||||
on_delete=django.db.models.deletion.CASCADE,
|
|
||||||
parent_link=True,
|
|
||||||
primary_key=True,
|
|
||||||
serialize=False,
|
|
||||||
to="wagtailcore.page",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
("intro", wagtail.fields.RichTextField(blank=True)),
|
("intro", wagtail.fields.RichTextField(blank=True)),
|
||||||
("thank_you_text", wagtail.fields.RichTextField(blank=True)),
|
("thank_you_text", wagtail.fields.RichTextField(blank=True)),
|
||||||
|
("allow_attachments", models.BooleanField(default=False)),
|
||||||
("from_address", models.EmailField(blank=True, help_text="Sender email address", max_length=254)),
|
("from_address", models.EmailField(blank=True, help_text="Sender email address", max_length=254)),
|
||||||
("to_address", models.CharField(help_text="Comma separated list of recipients", max_length=255)),
|
("to_address", models.CharField(help_text="Comma separated list of recipients", max_length=255)),
|
||||||
("subject", models.CharField(help_text="Subject of the email with data", max_length=255)),
|
("subject", models.CharField(help_text="Subject of the email with data", max_length=255)),
|
||||||
|
@ -39,7 +30,7 @@ class Migration(migrations.Migration):
|
||||||
options={
|
options={
|
||||||
"abstract": False,
|
"abstract": False,
|
||||||
},
|
},
|
||||||
bases=(wagtail.contrib.forms.models.FormMixin, "wagtailcore.page"),
|
bases=(wagtail.contrib.forms.models.FormMixin, models.Model),
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name="EmailFormSubmission",
|
name="EmailFormSubmission",
|
||||||
|
@ -115,7 +106,7 @@ class Migration(migrations.Migration):
|
||||||
),
|
),
|
||||||
("help_text", models.CharField(blank=True, max_length=255, verbose_name="help text")),
|
("help_text", models.CharField(blank=True, max_length=255, verbose_name="help text")),
|
||||||
(
|
(
|
||||||
"page",
|
"form",
|
||||||
modelcluster.fields.ParentalKey(
|
modelcluster.fields.ParentalKey(
|
||||||
on_delete=django.db.models.deletion.CASCADE,
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
related_name="form_fields",
|
related_name="form_fields",
|
||||||
|
|
|
@ -5,6 +5,7 @@ from django.conf import settings
|
||||||
from django.utils.formats import date_format
|
from django.utils.formats import date_format
|
||||||
|
|
||||||
from modelcluster.fields import ParentalKey
|
from modelcluster.fields import ParentalKey
|
||||||
|
from modelcluster.models import ClusterableModel
|
||||||
from wagtail.admin.panels import (
|
from wagtail.admin.panels import (
|
||||||
FieldPanel, FieldRowPanel,
|
FieldPanel, FieldRowPanel,
|
||||||
InlinePanel, MultiFieldPanel
|
InlinePanel, MultiFieldPanel
|
||||||
|
@ -12,7 +13,7 @@ from wagtail.admin.panels import (
|
||||||
from wagtail.fields import RichTextField
|
from wagtail.fields import RichTextField
|
||||||
from wagtail.contrib.forms.models import (
|
from wagtail.contrib.forms.models import (
|
||||||
AbstractFormField,
|
AbstractFormField,
|
||||||
AbstractForm,
|
FormMixin,
|
||||||
Page,
|
Page,
|
||||||
AbstractFormSubmission
|
AbstractFormSubmission
|
||||||
)
|
)
|
||||||
|
@ -20,13 +21,11 @@ from wagtail.contrib.forms.models import (
|
||||||
from mailings.models import send_mail
|
from mailings.models import send_mail
|
||||||
|
|
||||||
|
|
||||||
|
class Form(FormMixin, ClusterableModel):
|
||||||
class FormPage(AbstractForm):
|
|
||||||
adapter = None
|
|
||||||
|
|
||||||
intro = RichTextField(blank=True)
|
intro = RichTextField(blank=True)
|
||||||
thank_you_text = RichTextField(blank=True)
|
thank_you_text = RichTextField(blank=True)
|
||||||
|
allow_attachments = models.BooleanField(default=False)
|
||||||
|
|
||||||
content_panels = Page.content_panels + [
|
content_panels = Page.content_panels + [
|
||||||
FieldPanel('intro'),
|
FieldPanel('intro'),
|
||||||
InlinePanel('form_fields', label="Form fields"),
|
InlinePanel('form_fields', label="Form fields"),
|
||||||
|
@ -72,7 +71,7 @@ class EmailFormSubmission(AbstractFormSubmission):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class CustomEmailForm(FormPage):
|
class CustomEmailForm(Form):
|
||||||
from_address = models.EmailField(
|
from_address = models.EmailField(
|
||||||
blank=True,
|
blank=True,
|
||||||
help_text="Sender email address"
|
help_text="Sender email address"
|
||||||
|
@ -86,10 +85,10 @@ class CustomEmailForm(FormPage):
|
||||||
help_text="Subject of the email with data"
|
help_text="Subject of the email with data"
|
||||||
)
|
)
|
||||||
|
|
||||||
template = "forms/form_page.html"
|
template = "forms/email_form_page.html"
|
||||||
|
|
||||||
|
|
||||||
class EmailFormField(AbstractFormField):
|
class EmailFormField(AbstractFormField):
|
||||||
page = ParentalKey(
|
form = ParentalKey(
|
||||||
CustomEmailForm, related_name="form_fields", on_delete=models.CASCADE
|
"CustomEmailForm", related_name="form_fields", on_delete=models.CASCADE
|
||||||
)
|
)
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% load wagtailcore_tags wagtailimages_tags %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h1>{{ page.title }}</h1>
|
||||||
|
<p class="meta">{{ page.date }}</p>
|
||||||
|
|
||||||
|
<div class="body">{{ page.body|richtext }}</div>
|
||||||
|
|
||||||
|
{% for item in page.gallery_images.all %}
|
||||||
|
<div style="float: left; margin: 10px">
|
||||||
|
{% image item.image fill-320x240 %}
|
||||||
|
<p>{{ item.caption }}</p>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% endblock %}
|
Ładowanie…
Reference in New Issue