The scenario:
I have models like this:
class A(models.Model):
...
class B(models.Model):
a = models.ForeignKey(A)
...
In the admin I have something like this:
class AInlinde(admin.StackedInline):
...
model = A
...
class BAdmin(admin.ModelAdmin):
...
inlines = [AInline]
...
Now I need to record in a log when a user deletes some model in the inline, but I can’t follow the code, until now, I know Badmin have a method: save_formset, which is this:
def save_formset(self, request, form, formset, change):
"""
Given an inline formset save it to the database.
"""
formset.save()
but I think that formset is generated through the method modelformset_factory, so I can’t know when I can override the delete behavior of that formset
The best way for override how the formset saves or deletes the objects, is make a class that inherits from
BaseInlineFormSetand override the methodssaveandsave_existing_objects:Then construct a class than inherits from
StackedInline: