Open codematsing opened 1 month ago
Replicated: https://github.com/jrief/django-formset/compare/releases/1.5...codematsing:django-formset-debug:releases/1.5
How to test:
CompanyDepartmentUpdateView.form_kwargs
. It replicates the functionality of UpdateViews passing a form_kwargs["instance"]
to FormNotes: I did add my workaround so that form collection functionality will not interfere with self.instance data but I bet there's a better approach to this
Why is this important:
How I stumbled upon this issue
Company ||--o{ Department
would go as followclass CompanyDepartmentUpdateView(SingleObjectMixin, FormCollectionView):
model = Company
collection_class = CompanyDepartmentFormset
def form_collection_valid(self, form_collection):
form_collection.save()
class FormCollection(FormCollection):
department_formset = DepartmentForm()
def save(self):
for department_kwargs in self.cleaned_data['department_formset']:
Department.objects.create(company=self.instance, **deparment_kwargs)
Thanks for creating a runnable demo, appreciate that. I'll have a look at it.
Sure thing! I really love using your library and happy to help on improving on it!
Given
Expectation:
self.instance.name
should consistently be the parent_object.name passed inFormCollectionView.get_form_kwargs()
Actual Results:
self.instance.name
would refer to the last object child.name afterFormCollection.full_clean()
Observations:
Note: I'll to replicate this in django-formset using the repo. I'll get back to you on this as I'm swamped at the moment.