Ticket #5101: validate-on-save.diff

File validate-on-save.diff, 669 bytes (added by anonymous, 17 years ago)
  • django/db/models/base.py

    a b class Model(object):  
    282282                error_dict[f.name] = errors
    283283        return error_dict
    284284
     285    def validate_on_save(self):
     286        """
     287        perform validation before saving
     288        """
     289        errors = self.validate()
     290        if len(errors):
     291            from django.core import validators
     292            raise validators.ValidationError (errors)
     293        self.save()
     294
    285295    def _collect_sub_objects(self, seen_objs):
    286296        """
    287297        Recursively populates seen_objs with all objects related to this object.
Back to Top