what is the status/future of validation-aware models? is it planned to
have them in django-1.0? last year there was some activity regarding
them, so the models do have a validate() method, but it does not seem to
be complete.
if they are not planned for django-1.0:
is there a way to validate a model instance, that is not built from
from-data using a view, but using it's constructor in python-code?
gabor
> what is the status/future of validation-aware models? is it planned to
> have them in django-1.0? last year there was some activity regarding
> them, so the models do have a validate() method, but it does not seem to
> be complete.
As I wrote in another message I'm +1 on including that in 1.0 or more precisely in parallel with moving to the new forms.
> if they are not planned for django-1.0:
> is there a way to validate a model instance, that is not built from
> from-data using a view, but using it's constructor in python-code?
You can put all validation code in model validate() method and call it manually. I'm using something similar with the
new forms to validate uniqueness of the field data.
example:
obj = Model(<data>)
errors = obj.validate()
if not len(errors):
obj.save()
else:
<raise error, redisplay form, whatever>
You can also add call to the validate method in the save() to prevent saving model with invalid data like this:
...
def save(self):
errors = self.validate()
if len(errors):
raise validators.ValidationError ...
super(Model, self).save() # save data to the database
--
Nebojša Đorđević - nesh, ICQ#43799892
Studio Quattro - Niš - Serbia
http://studioquattro.biz/ | http://trac.studioquattro.biz/djangoutils/
Registered Linux User 282159 [http://counter.li.org]