Django - call original and overriden save method
Question: This may be a noobish question but it bothers me quite a lot (I'm quite new to
both django and python)

In my django app, I overrided the save() method of a model to perform some
interaction on the file system.

I created a form class like this :

    
    
    class AddItemForm(ModelForm):
        class Meta:
            model = OriginalModel
    

So, in my views, when I call form.save(), eveything works fine.

But, when testing my app, I'd like to be able to call the original save()
method to avoid creating plenty of files that I won't use and have to take
care of.

What I tried is to create a savebis() method, in order to preserve the
original save() method, but then how can I pass it to the ModelForm, so that I
can call form.save() or form.savebis()?

EDIT : savebis() is already written and working in my model. I want to be able
to call it from a modelform instance, but I don't know how to do this.


Answer: From your question, it sounds to me like you've got some optional processing
that should occur in the `Model`'s save method. As suggested in the question
comments, just add a `TESTING = True` type constant to your `settings.py` file
used during testing and check this value in the `Model` `save` method:

    
    
    from django.conf import settings
    
    class OriginalModel(Model):
        ...
        def save(self, *args, **kwargs):
            if not settings.TESTING:
                # Do some file system interaction, but not during testing.
                pass
            # Now save instance as per normal.
            return super(originalModel, self).save(*args, **kwargs)
    

If you go down the path of overriding the `ModelForm` `save` method then you
have to replicate existing functionality of the `ModelForm` `save` method, and
changing it to call you model's `savebis()` method instead of the `save()`
method. I'd advise against going down this path as it make the code more
complex than need be.

