Closed aidanlister closed 9 years ago
I think overriding has_changed
to return True
if any nested form has changed is a reasonable change. Is that something you're willing to put together a test + code for?
I implemented this as:
class ParentForm:
def has_changed(self):
return any([childform.has_changed() for childform in self.nested])
I'll write a test tonight (hopefully)
So I'd expect this to live on BaseNestedFormset
; if you look at that class, you'll see that it already overrides the save
method to first call its own save()
, then the nested grandchildren. Keep in mind that the base save
call saves the first two levels of forms, since BaseNestedFormset
subclasses BaseInlineFormSet
.
So I think it's something like:
def has_changed(self):
return super(self, ...).has_changed() and any([
child.nested.has_changed() for child in self
if
])
At that point I think has_changed
will return True
if anything has changed in either the base formset or the nested formsets.
Oh I see what you're saying -- just don't call the parent's form_valid() and we don't need to muck with the baseclass's save.
Would it make sense to propagate the has_changed value down from grandchildren forms to parent form?
Maybe adding a has_form_or_children_changed() with a better name?