At the moment, it doesn't seem that a developers can do pre-save/post- save work cleanly when dealing with Forms in NewForms Admin using django.newforms.models.ModelForm. For instance, if I'd like to send a notification email to a client once a form has been submitted for the first time (add_view), I'd have to override the models.ModelForm.save() method myself which inst very clean way to go about it.
My suggestion here would be to introduce some small changes at the django.newforms.models.BaseModelForm class level demonstrated in the diff below. This way the developers can overwrite one or all of the event methods namely pre_save(), post_save(). Index: django/newforms/models.py =================================================================== --- django/newforms/models.py (revision 7512) +++ django/newforms/models.py (working copy) @@ -262,6 +262,12 @@ BaseForm.__init__(self, data, files, auto_id, prefix, object_data, error_class, label_suffix, empty_permitted) + def pre_save(self, is_new_data): + pass + + def post_save(self, is_new_data): + pass + def save(self, commit=True): """ Saves this ``form``'s cleaned_data into model instance @@ -272,10 +278,22 @@ """ if self.instance.pk is None: fail_message = 'created' + new_data = True else: fail_message = 'changed' - return save_instance(self, self.instance, self._meta.fields, fail_message, commit) + new_data = False + # do some pre-save logic here + self.pre_save(new_data) + + result_instance = save_instance(self, self.instance, self._meta.fields, fail_message, commit) + + # do some post-save logic here + if result_instance is not None: self.post_save(new_data) + + return result_instance + + class ModelForm(BaseModelForm): __metaclass__ = ModelFormMetaclass Regards, -Alen --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---