forked from beba/foerderbarometer
Add custom save() in CheckForm to map 'check' field to model's 'terms_accepted'
This commit is contained in:
parent
32f8a8f50f
commit
0efaa6910d
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Reference in New Issue