1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #24706 -- Made ModelForm._post_clean() handle a ValidationError raised when constructing the model instance.

Thanks Loïc Bistuer for review and advice.
This commit is contained in:
Keryn Knight
2015-04-30 08:57:30 +01:00
committed by Tim Graham
parent 8e84d9c844
commit 3c5862ccb0
3 changed files with 74 additions and 5 deletions

View File

@@ -453,3 +453,24 @@ class Photo(models.Model):
class UUIDPK(models.Model):
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField(max_length=30)
# Models for #24706
class StrictAssignmentFieldSpecific(models.Model):
title = models.CharField(max_length=30)
_should_error = False
def __setattr__(self, key, value):
if self._should_error is True:
raise ValidationError(message={key: "Cannot set attribute"}, code='invalid')
super(StrictAssignmentFieldSpecific, self).__setattr__(key, value)
class StrictAssignmentAll(models.Model):
title = models.CharField(max_length=30)
_should_error = False
def __setattr__(self, key, value):
if self._should_error is True:
raise ValidationError(message="Cannot set attribute", code='invalid')
super(StrictAssignmentAll, self).__setattr__(key, value)