Am 22.02.2006 um 08:12 schrieb Adrian Holovaty: > Let's return to this subject, which was discussed a couple of weeks > ago. Here's my latest thinking on the subject. > > * Automatic manipulators go away. Instead of messing with those, to > create a new model object you try instantiating it. Validation errors > are raised at that point. Example: > > try: > c = Crime(crime_date='2006-1-2', crime_type='theft') > except ValidationError: > print "You have errors." > > # Getting the errors > > try: > c = Crime(crime_date='2006-1-2', crime_type='theft') > except ValidationError, e: > print e.messages # prints list of error messages (as strings) > > * Specifically, validation happens on Model.__init__() and > Model.__setattr(), except when model objects are being loaded from the > database (e.g. Model.objects.get()). In the latter case, we can assume > the data is valid.
Why not do the validation on Model.save(). The developer can not "forget to validate", but the model instance is allowed to be invalid temporarily, until it is fully populated and actually gets saved. Cheers, Chris -- Christopher Lenz cmlenz at gmx.de http://www.cmlenz.net/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers -~----------~----~----~----~------~----~------~--~---