Last active
April 15, 2022 07:39
-
-
Save corcoran/5b0197e0ba0b56eee09bd6315fe306da to your computer and use it in GitHub Desktop.
Modify Inline FormSet in Django Admin after validation and before save
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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