Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quevon24/92fdbcc722217f4aeeec99001cbdacff to your computer and use it in GitHub Desktop.
Save quevon24/92fdbcc722217f4aeeec99001cbdacff to your computer and use it in GitHub Desktop.
Hidden delete inline formset base class for Django.
class HiddenDeleteBaseInlineFormSet(BaseInlineFormSet):
"""
Makes the delete field a hidden input rather than the default checkbox
inlineformset_factory(Book, Page, formset=HiddenDeleteBaseInlineFormSet, can_delete=True)
"""
def add_fields(self, form, index):
super(HiddenDeleteBaseInlineFormSet, self).add_fields(form, index)
if self.can_delete:
form.fields[DELETION_FIELD_NAME] = forms.BooleanField(
label=_('Delete'),
required=False,
widget=forms.HiddenInput
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment