Hey everyone, I have probably a very simple question, that i haven’t been able to figure out for a while.
Our django application had a hard crash whenever someone would delete anything in the administration panel. After narrowing it down to the following piece of code i found out what the problem was:
def save_related(self, request, form, formsets, change):
for single_form in formsets:
if single_form.model == Malfunction and single_form.has_changed():
new_instance = single_form.save(commit=False)[0]
This is part of a class that extends ModelAdmin, and i omitted what comes after it for brevity. What this part is supposed to do, is when a related object has been changed, and the related object is of type Malfunction, it gets the changed instance of it.
My question is now however, if such an object has been deleted instead of changed, how can i check for that? Because if it has been deleted, that form.save() call will fail.