Skip to content

Instantly share code, notes, and snippets.

@igniteflow
Last active March 16, 2021 22:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save igniteflow/335ffed5c7a3d909c61e to your computer and use it in GitHub Desktop.
Save igniteflow/335ffed5c7a3d909c61e 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
)
@oginga
Copy link

oginga commented Dec 2, 2017

Awesome .
Addition
from django.forms import BaseInlineFormset

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment