The implementation is largely inspired from another oursky project, particularly on the usage of modified django_superform library, and the structures of QuestionForm and the form set forms.
Current behaviours:
User can add new and delete existing rows from related tables
User trying to modify an existing entry will keep the original entry unmodified and create a new entry with the new data. This is caused by the save function in the FormSetForm class, which assumes all data to be saved are new data and thus new objects are created.
Implementation details:
The django_superform library provides methods to create nested forms without needing to manually handle the validations and saving. We mainly use their SuperModelForm and InlineFormSetField classes in the implementation.
The superform/formsetfield.html template use to render InlineFormSetField is customized to use Material UI. The material/frontend/views/form.html and material/layout/fieldset.html templates are referenced for the customisations.
For forms utilizing the django_superform library, a Meta inner class is needed to store the model and fields used.
In QuestionForm, each related model have an associated InlineFormSetField, and the header and initial data shown in the form is passed from the __init__() function using querysets.
For forms relating to InlineFormSetField, the parent_instance_field marks which field in the model links back to the parent model. The FormSetForm superclass handles the initialization and saving, and is based on ideas from the referenced project.
Current behaviours:
User can add new and delete existing rows from related tables
User trying to modify an existing entry will keep the original entry unmodified and create a new entry with the new data. This is caused by the save function in the FormSetForm class, which assumes all data to be saved are new data and thus new objects are created.
Related findings:
In the BaseModelFormSet class from django.forms.models, there are separate function for saving new and existing objects (save_new() vs save_existing()), but they use the same form.save() function to do so.
In the BaseInlineFormSet class from django.forms.models, the save_new() function is modified so that the related (parent) instance is saved to the form before calling BaseModelFormSet's save_new() function.
connect oursky#7
The implementation is largely inspired from another oursky project, particularly on the usage of modified
django_superform
library, and the structures ofQuestionForm
and the form set forms.Current behaviours:
save
function in theFormSetForm
class, which assumes all data to be saved are new data and thus new objects are created.Implementation details:
django_superform
library provides methods to create nested forms without needing to manually handle the validations and saving. We mainly use theirSuperModelForm
andInlineFormSetField
classes in the implementation.superform/formsetfield.html
template use to renderInlineFormSetField
is customized to use Material UI. Thematerial/frontend/views/form.html
andmaterial/layout/fieldset.html
templates are referenced for the customisations.django_superform
library, aMeta
inner class is needed to store the model and fields used.QuestionForm
, each related model have an associatedInlineFormSetField
, and the header and initial data shown in the form is passed from the__init__()
function using querysets.InlineFormSetField
, theparent_instance_field
marks which field in the model links back to the parent model. TheFormSetForm
superclass handles the initialization and saving, and is based on ideas from the referenced project.Current behaviours:
save
function in theFormSetForm
class, which assumes all data to be saved are new data and thus new objects are created.Related findings:
BaseModelFormSet
class fromdjango.forms.models
, there are separate function for saving new and existing objects (save_new()
vssave_existing()
), but they use the sameform.save()
function to do so.BaseInlineFormSet
class fromdjango.forms.models
, thesave_new()
function is modified so that the related (parent) instance is saved to the form before callingBaseModelFormSet
'ssave_new()
function.