[Fixed]-How to customise django inline admin form's delete function


You should define a custom Formset and override the delete behaviour. Here’s the code:

class ChildFormSet(BaseInlineFormSet):
    def delete_existing(self, obj, commit=True):
        obj.parent = None
        if commit:

class ChildModelInline(admin.TabularInline):
    model = ChildModel
    formset = ChildFormSet

class ParentModelAdmin(admin.ModelAdmin):
    inlines = [ChildModelInline,]


What all you can do is first define a custom action for the respective model and in that action just put the models.ForeignKey field to null.So it will remove the child parent relation between the objects but it won’t delete the object from the database.


It can be controlled from the on_delete attribute of model property. Lookinto the below line:

option = models.ForeignKey(ServiceOption, on_delete=models.CASCADE, related_name='additional')

Leave a comment