On Friday, September 19, 2014 at 1:21:22 AM UTC+2, scott baker wrote: > > I've modified an Admin with code similar to the following: > > def save_formset(self, request, form, formset, change): > instances = formset.save(commit=False) > for instance in instances: > instance.user = request.user > instance.save() > formset.save_m2m() > > > The problem I'm having is that if a "delete" checkbox is checked, the > inline does not get deleted. I tracked this down to > forms/models.py:save_existing_objects(). In Django 1.5 it deleted objects > regardless of the setting of the commit argument. In django 1.7, it does > not delete the objects if commit==False. > > Am I missing something in the above that I need to do in order to cause my > deleted inlines to be deleted? I can do it by looping through > formset.deleted_forms myself (basically duplicating the code from > save_existing_objects), but this feels like the wrong way to go about it. > > Thanks, > Scott >
Hello from the future! This should work: def save_formset(self, request, form, formset, change): print(formset) instances = formset.save(commit=False) for obj in formset.deleted_objects: obj.delete() for instance in instances: instance.created_by = request.user instance.created_at = timezone.now() # Do something with `instance` instance.save() formset.save_m2m() -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3d85fa84-5c14-48fd-9f73-955869c10a18o%40googlegroups.com.