Skip to content

Instantly share code, notes, and snippets.

@corcoran
Last active April 15, 2022 07:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save corcoran/5b0197e0ba0b56eee09bd6315fe306da to your computer and use it in GitHub Desktop.
Save corcoran/5b0197e0ba0b56eee09bd6315fe306da to your computer and use it in GitHub Desktop.
Modify Inline FormSet in Django Admin after validation and before save
class InlineScreenshotFormSet(forms.models.BaseInlineFormSet):
def clean(self):
index = 0
for error in self._errors:
# If inline 'title' field is empty, fetch title from parent instead
if 'title' in error:
del self._errors[index]['title']
self.forms[index].instance.title = self.data['title']
self.forms[index].cleaned_data['title'] = self.data['title']
index += 1
return super(InlineScreenshotFormSet, self).clean()
class ScreenshotInline(admin.TabularInline):
formset = InlineScreenshotFormSet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment