Ticket #14099: model-formset-delete.diff

File model-formset-delete.diff, 2.1 KB (added by kenth, 14 years ago)

patch for BaseModelFormSet to use BaseFormSet._should_delete_form

  • django/forms/models.py

    diff --git a/django/forms/models.py b/django/forms/models.py
    index f2d514f..8f6b700 100644
    a b from forms import BaseForm, get_declared_fields  
    1616from fields import Field, ChoiceField
    1717from widgets import SelectMultiple, HiddenInput, MultipleHiddenInput
    1818from widgets import media_property
    19 from formsets import BaseFormSet, formset_factory, DELETION_FIELD_NAME
     19from formsets import BaseFormSet, formset_factory
    2020
    2121__all__ = (
    2222    'ModelForm', 'BaseModelForm', 'model_to_dict', 'fields_for_model',
    class BaseModelFormSet(BaseFormSet):  
    609609            pk_value = getattr(pk_value, 'pk', pk_value)
    610610
    611611            obj = self._existing_object(pk_value)
    612             if self.can_delete:
    613                 raw_delete_value = form._raw_value(DELETION_FIELD_NAME)
    614                 should_delete = form.fields[DELETION_FIELD_NAME].clean(raw_delete_value)
    615                 if should_delete:
    616                     self.deleted_objects.append(obj)
    617                     obj.delete()
    618                     continue
     612            if self.can_delete and self._should_delete_form (form):
     613                self.deleted_objects.append(obj)
     614                obj.delete()
     615                continue
    619616            if form.has_changed():
    620617                self.changed_objects.append((obj, form.changed_data))
    621618                saved_instances.append(self.save_existing(form, obj, commit=commit))
    class BaseModelFormSet(BaseFormSet):  
    630627                continue
    631628            # If someone has marked an add form for deletion, don't save the
    632629            # object.
    633             if self.can_delete:
    634                 raw_delete_value = form._raw_value(DELETION_FIELD_NAME)
    635                 should_delete = form.fields[DELETION_FIELD_NAME].clean(raw_delete_value)
    636                 if should_delete:
    637                     continue
     630            if self.can_delete and self._should_delete_form (form):
     631                continue
    638632            self.new_objects.append(self.save_new(form, commit=commit))
    639633            if not commit:
    640634                self.saved_forms.append(form)
Back to Top