Reputation: 1297
I'd like to check the DELETE checkbox in inline formset... but I'd like to check only the "extra" lines (rows) e.g. when editing I'd like the populated lines (rows) to remain unchecked, but the extra ones checked until I uncheck them (I'll probably check for the content of input fields with js).
I've managed to check the filled (in editing) lines (rows), but the extra ones remained unchecked... with the following code under init:
self.initial[DELETION_FIELD_NAME] = True
Then I've tried the following under Meta > Widgets:
DELETION_FIELD_NAME:CheckboxInput(attrs={'checked':'checked','class':'test',}),
Which didn't work... I can't even set the class of the checkbox...
EDIT: This is not in admin inline formset.
Thanks!
Upvotes: 0
Views: 2552
Reputation: 2263
you can do this by iterating trough the formset:
for f in formset.initial_forms:
f.fields["DELETE"].initial = True
for f in formset.extra_forms:
f.fields["DELETE"].initial = False
I hope this helped.
Upvotes: 1