Ticket #18508: django-forms-bug.patch
File django-forms-bug.patch, 3.9 KB (added by , 12 years ago) |
---|
-
django/forms/models.py
diff --git a/django/forms/models.py b/django/forms/models.py index 26f8691..42f46a7 100644
a b class BaseModelFormSet(BaseFormSet): 447 447 if isinstance(pk, list): 448 448 pk = pk[0] 449 449 kwargs['instance'] = self._existing_object(pk) 450 if i < self.initial_form_count() and not kwargs.get('instance'):450 elif i < self.initial_form_count() and not kwargs.get('instance'): 451 451 kwargs['instance'] = self.get_queryset()[i] 452 452 if i >= self.initial_form_count() and self.initial_extra: 453 453 # Set initial values for extra forms -
tests/regressiontests/forms/models.py
diff --git a/tests/regressiontests/forms/models.py b/tests/regressiontests/forms/models.py index 18e6ddc..b1151e6 100644
a b class Group(models.Model): 75 75 76 76 class Cheese(models.Model): 77 77 name = models.CharField(max_length=100) 78 79 80 class DirectoryModel(models.Model): 81 name = models.CharField(max_length=100) 82 83 class EntryModel(models.Model): 84 name = models.CharField(max_length=100) 85 directory = models.ForeignKey(DirectoryModel) -
tests/regressiontests/forms/tests/__init__.py
diff --git a/tests/regressiontests/forms/tests/__init__.py b/tests/regressiontests/forms/tests/__init__.py index 8e2150c..ce43669 100644
a b from .input_formats import (LocalizedTimeTests, CustomTimeInputFormatsTests, 13 13 CustomDateTimeInputFormatsTests, SimpleDateTimeFormatTests) 14 14 from .media import FormsMediaTestCase, StaticFormsMediaTestCase 15 15 from .models import (TestTicket12510, ModelFormCallableModelDefault, 16 FormsModelTestCase, RelatedModelFormTests )16 FormsModelTestCase, RelatedModelFormTests, FormsModelFormsetTestCase) 17 17 from .regressions import FormsRegressionsTestCase 18 18 from .util import FormsUtilTestCase 19 19 from .validators import TestFieldWithValidators -
tests/regressiontests/forms/tests/models.py
diff --git a/tests/regressiontests/forms/tests/models.py b/tests/regressiontests/forms/tests/models.py index 5bea49b..9b063ce 100644
a b import datetime 6 6 from django.core.files.uploadedfile import SimpleUploadedFile 7 7 from django.db import models 8 8 from django.forms import Form, ModelForm, FileField, ModelChoiceField 9 from django.forms.models import ModelFormMetaclass 9 from django.forms.models import ModelFormMetaclass, inlineformset_factory 10 10 from django.test import TestCase 11 11 12 12 from ..models import (ChoiceOptionModel, ChoiceFieldModel, FileModel, Group, 13 BoundaryModel, Defaults )13 BoundaryModel, Defaults, DirectoryModel, EntryModel) 14 14 15 15 16 16 class ChoiceFieldForm(ModelForm): … … class RelatedModelFormTests(TestCase): 196 196 model=A 197 197 198 198 self.assertTrue(issubclass(ModelFormMetaclass(b'Form', (ModelForm,), {'Meta': Meta}), ModelForm)) 199 200 class EntryModelForm(ModelForm): 201 class Meta: 202 model = EntryModel 203 204 EntryModelFormset = inlineformset_factory(DirectoryModel, EntryModel, EntryModelForm) 205 206 class FormsModelFormsetTestCase(TestCase): 207 def test_model_formset_outdated_deletion(self): 208 d = DirectoryModel.objects.create(name="dir") 209 e = EntryModel.objects.create(name="foo", directory=d) 210 211 # we only have id=1, id=2 doesn't exist 212 formset = EntryModelFormset(data={'form-INITIAL_FORMS':'2', 'form-TOTAL_FORMS':'2', 'form-0-id':'1', 'form-0-name':'bah', 'form-1-id':'2', 'form-1-name':'baz', 'form-1-DELETE': 'on', }, prefix="form", instance=d) 213 214 # id=1 is good, id=2 is gone but that doesn't matter as we're deleting it 215 self.assertTrue(formset.is_valid()) 216 217 formset.save() 218 219 self.assertEquals(EntryModel.objects.get(pk=e.pk).name, "bah") 220 # should have ignored id=2 221 self.assertEquals(d.entrymodel_set.count(), 1) 222 self.assertEquals(EntryModel.objects.filter(pk=2).count(), 0)