1
0
mirror of https://github.com/django/django.git synced 2025-10-25 22:56:12 +00:00

[soc2009/model-validation] Added validators to DbFields

ComplexValidators are not yet run on the model and custom message
overring is still not in place

git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/model-validation@11037 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Honza Král
2009-06-18 00:59:07 +00:00
parent d06bca726d
commit 3a331970b4
3 changed files with 55 additions and 21 deletions

View File

@@ -4,11 +4,17 @@ from django.core.exceptions import ValidationError
from django.db import models
from django.test import TestCase
def validate_answer_to_universe(value):
if value != 42:
raise ValidationError('This is not the answer to life, universe and everything!')
class ModelToValidate(models.Model):
name = models.CharField(max_length=100)
created = models.DateTimeField(default=datetime.now)
number = models.IntegerField()
parent = models.ForeignKey('self', blank=True, null=True)
email = models.EmailField(blank=True)
f_with_custom_validator = models.IntegerField(blank=True, null=True, validators=[validate_answer_to_universe])
def validate(self):
super(ModelToValidate, self).validate()