Skip to content

Instantly share code, notes, and snippets.

@danilovmy
Created May 9, 2022 13:36
Show Gist options
  • Save danilovmy/59f76be725fc2bcdcd0ccb89fe8f7696 to your computer and use it in GitHub Desktop.
Save danilovmy/59f76be725fc2bcdcd0ccb89fe8f7696 to your computer and use it in GitHub Desktop.
form prefix handling for nested inlines
class MyForm(StackedInline.form):
def __init__(self, *args, **kwargs):
super(MyForm, self).__init__(*args, **kwargs)
self.instance.form = self
class ProductInline(StackedInline):
# ......
form = MyForm
def image_inline(self, obj=None, *args, **kwargs):
# ......
inline.formset.prefix = f'{inline.formset.prefix}_{obj.form.prefix}'.replace('-', '_')
# ......
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment