From 0efaa6910d13fd17041abff5d713055bb261db74 Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 26 Aug 2025 15:37:33 +0200 Subject: [PATCH] Add custom save() in CheckForm to map 'check' field to model's 'terms_accepted' --- input/forms.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/input/forms.py b/input/forms.py index 32d40d6..0ee0237 100755 --- a/input/forms.py +++ b/input/forms.py @@ -164,7 +164,23 @@ class CheckForm(FdbForm): ) ) + def save(self, commit=True): + """Save the form instance and map the 'check' field to the model's 'terms_accepted' field, saving to the database if commit=True.""" + # Call the parent form's save() method with commit=False + # to get a model instance without saving it to the database yet. + instance = super().save(commit=False) + # If the model has a "terms_accepted" field, + # copy the value from the form field "check" into it. + if hasattr(instance, "terms_accepted"): + instance.terms_accepted = bool(self.cleaned_data.get('check')) + + # If commit=True (default), save the instance to the database now. + if commit: + instance.save() + + # Return the model instance (saved if commit=True, otherwise unsaved). + return instance """Baseclass for all classes which need a check for Nutzungsbedingungen""" # def __init__(self, *args, **kwargs):