I have created custom validators to my models fields, but I don't
know if it is possible to create a validator for a field that use the
value of other field in its validator.
What I am trying to do:
I have this model:
class MyModel(models.Model):
field1 = models.IntegerField()
field2 = models.IntegerField(validators=[my_validator])
And then I want to create a custom validator:
def my_validator(value):
field2_value = value
field1_value = ??? # Can I get this value???
# Just a example of validation
if field1_value > field2_value:
# do something
else:
raise ValidationError('My error!!!')
Is it possible to do this? Or the only way to validate the
relationship between two fields is with form validation?
Thank you!
Renne Rocha
renne...@gmail.com
http://rennerocha.webfactional.com/
this may help:
http://docs.djangoproject.com/en/dev/ref/models/instances/?from=olddo#id1
--
regards
Kenneth Gonsalves
I must define the Model.clean() method.
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to django-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>
>