Ticket #14877: django-formset-delete-bug.patch

File django-formset-delete-bug.patch, 1.1 KB (added by Ole Laursen, 11 years ago)

Replace needless (re)-cleaning of form with just picking the already assigned form.instance

  • django/forms/models.py

    diff --git a/django/forms/models.py b/django/forms/models.py
    index 26f8691..459c5dd 100644
    a b class BaseModelFormSet(BaseFormSet):  
    596596
    597597        saved_instances = []
    598598        for form in self.initial_forms:
    599             pk_name = self._pk_field.name
    600             raw_pk_value = form._raw_value(pk_name)
    601 
    602             # clean() for different types of PK fields can sometimes return
    603             # the model instance, and sometimes the PK. Handle either.
    604             pk_value = form.fields[pk_name].clean(raw_pk_value)
    605             pk_value = getattr(pk_value, 'pk', pk_value)
    606 
    607             obj = self._existing_object(pk_value)
     599            obj = form.instance
    608600            if self.can_delete and self._should_delete_form(form):
    609601                self.deleted_objects.append(obj)
    610                 obj.delete()
     602                if obj.pk != None:
     603                    obj.delete()
    611604                continue
    612605            if form.has_changed():
    613606                self.changed_objects.append((obj, form.changed_data))
Back to Top