feat(formbuilder): answers must belong to the submission's form

An Answer's field could point at a field of a *different* form than its
submission — and since forms are club-scoped, across clubs too. Validate
field.form == submission.form in clean().

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-13 14:42:17 +02:00
parent 22d971d48c
commit d43ca0cfa8
2 changed files with 23 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
from django.core.exceptions import ValidationError
from django.db import models
from django.db.models import UniqueConstraint
from django.utils.translation import gettext_lazy as _
@@ -100,3 +101,7 @@ class Answer(UUIDModel):
def __str__(self):
return f"{self.submission} - {self.field}"
def clean(self):
if self.field_id and self.submission_id and self.field.form_id != self.submission.form_id:
raise ValidationError({"field": _("Must belong to the same form as the submission.")})