Store contact form submissions in Wagtail admin

This commit is contained in:
2026-05-09 11:05:20 +02:00
parent df28667a9c
commit 3b02100f75
5 changed files with 218 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
import uuid
from django.conf import settings
from django.db import models
from django.utils.translation import gettext_lazy as _
@@ -102,3 +103,47 @@ class LocaleAuditIssue(models.Model):
class Meta:
ordering = ["locale_code", "url", "field_path"]
class ContactMessage(models.Model):
created_at = models.DateTimeField(auto_now_add=True, db_index=True)
site = models.ForeignKey(
Site, on_delete=models.PROTECT, related_name="contact_messages"
)
locale = models.ForeignKey(
Locale, on_delete=models.PROTECT, related_name="contact_messages"
)
user = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.SET_NULL,
null=True,
blank=True,
related_name="contact_messages",
)
ip_address = models.GenericIPAddressField(null=True, blank=True)
path = models.CharField(max_length=255, blank=True)
name = models.CharField(max_length=200)
email = models.EmailField()
phone_number = models.CharField(max_length=64, blank=True)
message = models.TextField()
panels = [
FieldPanel("site"),
FieldPanel("locale"),
FieldPanel("user"),
FieldPanel("ip_address"),
FieldPanel("path"),
FieldPanel("name"),
FieldPanel("email"),
FieldPanel("phone_number"),
FieldPanel("message"),
]
class Meta:
ordering = ["-created_at"]
verbose_name = _("Contact message")
verbose_name_plural = _("Contact messages")
def __str__(self):
return f"{self.created_at:%Y-%m-%d %H:%M} - {self.name}"