-
Notifications
You must be signed in to change notification settings - Fork 45
Open
Description
Given
#models.py
class ParentModel(self):
name = models.CharField
class ChildModel(self):
parent = models.ForeignKey(Parent, related_name='children', on_delete=models.CASCADE)
name = models.CharField
#forms.py
class ChildForm(ModelForm):
class Meta:
model = ChildModel()
fields = '__all__'
class ParentChildFormCollection(FormCollection):
child_formset = ChildForm()
class UpdateView(SingleObjectMixin, FormCollectionView):
model = ParentModel
collection_class = ParentChildFormCollection()
def get_initial():
parent_object = self.get_object()
initial = [
{"child_form": {child.name for child in parent.children.all()}}
]
return initialExpectation:
#forms.py
class ParentChildFormCollection():
def save(self):
logger.info(self.instance.name)
logger.info(type(self.instance))
...- Expectation
self.instance.nameshould consistently be the parent_object.name passed inFormCollectionView.get_form_kwargs()
Actual Results:
self.instance.namewould refer to the last object child.name afterFormCollection.full_clean()
Observations:
# in class FormCollection
def full_clean(self):
...
logger.info(instance) #print parent_name
if holder.is_valid():
valid_holders[name] = holder
logger.info(instance) #prints_child_name
...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.
Metadata
Metadata
Assignees
Labels
No labels