4

I have Admin model which has inline model with its form e.g

class ParentAdmin(admin.Model):
  inlines = (ChildInline,)


class ChildInline(admin.TabularInline):
  ..
  form = ChildInlineForm
  ..


class ChildInlineForm(forms.ModelForm):
   def clean(self):
      ....

My clean() method logic is not coming along because of my business logic. I need to validated all inline objects as a set and some might depend on each other, so I need all posted inline objects before validation.

E.g an instance of child C is only validated or expected when child A is in the set. Since form is dirty and value might be in the db or not. I need to intercept all the child instances before validation (e.g clean is called on any of the instance) and pass the set to validation function e.g

 class ChildInlineForm(forms.ModelForm):
       def clean(self):
         self.instance.parentobj.__dirtychildren=#desired logic
         self.instance.validate(self.instance.parentobj)

I looked at admin model code, I dont see any suitable way to add this functionality. Not in save_formset , save_related, etc. The example code I put is hypothetical as the actual code very complex to cut-and-past

sakhunzai
  • 13,900
  • 23
  • 98
  • 159

0 Answers0