Loading django/forms/models.py +1 −1 Original line number Diff line number Diff line Loading @@ -454,7 +454,7 @@ class BaseModelForm(BaseForm): If commit=True, then the changes to ``instance`` will be saved to the database. Returns ``instance``. """ if self.instance.pk is None: if self.instance._state.adding: fail_message = 'created' else: fail_message = 'changed' Loading tests/model_forms/models.py +6 −0 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ from __future__ import unicode_literals import datetime import os import tempfile import uuid from django.core import validators from django.core.exceptions import ValidationError Loading Loading @@ -447,3 +448,8 @@ class Photo(models.Model): def save(self, force_insert=False, force_update=False): super(Photo, self).save(force_insert, force_update) self._savecount += 1 class UUIDPK(models.Model): uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) name = models.CharField(max_length=30) tests/model_forms/test_uuid.py 0 → 100644 +29 −0 Original line number Diff line number Diff line from __future__ import unicode_literals from django import forms from django.test import TestCase from .models import UUIDPK class UUIDPKForm(forms.ModelForm): class Meta: model = UUIDPK fields = '__all__' class ModelFormBaseTest(TestCase): def test_create_save_error(self): form = UUIDPKForm({}) self.assertFalse(form.is_valid()) msg = "The UUIDPK could not be created because the data didn't validate." with self.assertRaisesMessage(ValueError, msg): form.save() def test_update_save_error(self): obj = UUIDPK.objects.create(name='foo') form = UUIDPKForm({}, instance=obj) self.assertFalse(form.is_valid()) msg = "The UUIDPK could not be changed because the data didn't validate." with self.assertRaisesMessage(ValueError, msg): form.save() tests/model_forms/tests.py +1 −1 Original line number Diff line number Diff line Loading @@ -1978,7 +1978,7 @@ class FileAndImageFieldTests(TestCase): form = FPForm() names = [p[1] for p in form['path'].field.choices] names.sort() self.assertEqual(names, ['---------', '__init__.py', 'models.py', 'tests.py']) self.assertEqual(names, ['---------', '__init__.py', 'models.py', 'test_uuid.py', 'tests.py']) @skipUnless(test_images, "Pillow not installed") def test_image_field(self): Loading Loading
django/forms/models.py +1 −1 Original line number Diff line number Diff line Loading @@ -454,7 +454,7 @@ class BaseModelForm(BaseForm): If commit=True, then the changes to ``instance`` will be saved to the database. Returns ``instance``. """ if self.instance.pk is None: if self.instance._state.adding: fail_message = 'created' else: fail_message = 'changed' Loading
tests/model_forms/models.py +6 −0 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ from __future__ import unicode_literals import datetime import os import tempfile import uuid from django.core import validators from django.core.exceptions import ValidationError Loading Loading @@ -447,3 +448,8 @@ class Photo(models.Model): def save(self, force_insert=False, force_update=False): super(Photo, self).save(force_insert, force_update) self._savecount += 1 class UUIDPK(models.Model): uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) name = models.CharField(max_length=30)
tests/model_forms/test_uuid.py 0 → 100644 +29 −0 Original line number Diff line number Diff line from __future__ import unicode_literals from django import forms from django.test import TestCase from .models import UUIDPK class UUIDPKForm(forms.ModelForm): class Meta: model = UUIDPK fields = '__all__' class ModelFormBaseTest(TestCase): def test_create_save_error(self): form = UUIDPKForm({}) self.assertFalse(form.is_valid()) msg = "The UUIDPK could not be created because the data didn't validate." with self.assertRaisesMessage(ValueError, msg): form.save() def test_update_save_error(self): obj = UUIDPK.objects.create(name='foo') form = UUIDPKForm({}, instance=obj) self.assertFalse(form.is_valid()) msg = "The UUIDPK could not be changed because the data didn't validate." with self.assertRaisesMessage(ValueError, msg): form.save()
tests/model_forms/tests.py +1 −1 Original line number Diff line number Diff line Loading @@ -1978,7 +1978,7 @@ class FileAndImageFieldTests(TestCase): form = FPForm() names = [p[1] for p in form['path'].field.choices] names.sort() self.assertEqual(names, ['---------', '__init__.py', 'models.py', 'tests.py']) self.assertEqual(names, ['---------', '__init__.py', 'models.py', 'test_uuid.py', 'tests.py']) @skipUnless(test_images, "Pillow not installed") def test_image_field(self): Loading