Ticket #10363: exclude-save.diff

File exclude-save.diff, 2.0 KB (added by Alex Gaynor, 16 years ago)
  • django/forms/models.py

    diff --git a/django/forms/models.py b/django/forms/models.py
    index 010d3bf..de5f1ab 100644
    a b class BaseModelForm(BaseForm):  
    334334            fail_message = 'created'
    335335        else:
    336336            fail_message = 'changed'
    337         return save_instance(self, self.instance, self._meta.fields, fail_message, commit)
     337        return save_instance(self, self.instance, self._meta.fields,
     338                             fail_message, commit, exclude=self._meta.exclude)
    338339
    339340    save.alters_data = True
    340341
  • tests/regressiontests/forms/models.py

    diff --git a/tests/regressiontests/forms/models.py b/tests/regressiontests/forms/models.py
    index 1575953..8a5e312 100644
    a b True  
    4242{'file1': <SimpleUploadedFile: 我隻氣墊船裝滿晒鱔.txt (text/plain)>}
    4343>>> m = FileModel.objects.create(file=f.cleaned_data['file1'])
    4444
    45 # It's enough that m gets created without error.  Preservation of the exotic name is checked 
     45# It's enough that m gets created without error.  Preservation of the exotic name is checked
    4646# in a file_uploads test; it's hard to do that correctly with doctest's unicode issues. So
    4747# we create and then immediately delete m so as to not leave the exotically named file around
    4848# for shutil.rmtree (on Windows) to have trouble with later.
    u'instance value'  
    8585datetime.date(1969, 4, 4)
    8686>>> instance_form.initial['value']
    878712
     88
     89>>> from django.forms import CharField
     90>>> class ExcludingForm(ModelForm):
     91...     name = CharField(max_length=256)
     92...     class Meta:
     93...         model = Defaults
     94...         exclude = ['name']
     95>>> f = ExcludingForm({'name': u'Hello', 'value': 99, 'def_date': datetime.date(1999, 3, 2)})
     96>>> f.is_valid()
     97True
     98>>> f.cleaned_data['name']
     99u'Hello'
     100>>> obj = f.save()
     101>>> obj.name
     102u'class default value'
     103>>> obj.value
     10499
     105>>> obj.def_date
     106datetime.date(1999, 3, 2)
    88107>>> shutil.rmtree(temp_storage_location)
    89108"""}
Back to Top