* gabor wrote, On 14.01.2007 12:19:
hi,
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]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django
developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---