[Answer]-Use method of model class within save method

1👍

You should put args and kwargs to overridden save()method too:

class MyModel(models.Model):
    name = models.CharField(max_length=255)

    def do_something(self):
        pass

    def save(self, *args, **kwargs):
        self.do_something()
        super(MyModel, self).save(*args, **kwargs)

You also forgot self parameter in do_something()!

UPDATE

I don’t quite understand your problem. If you want to call unbound method do_something, define it outside the class MyModel with one and just call it from save() like `do_something(self):

class MyModel(class.Model):
  def save(self, *args, **kwargs):
    do_something(self)
    super(MyModel, self).save(*args, **kwargs)

def do_someting(my_model_instance):
  assert isinstance(my_model_instance, MyModel)
  ...

Leave a comment