I know this question is old, but I was looking for an answer to this earlier today, so why not. It seems from your code you really wanted to use the instance method (from self and field assignment). DataGreed turned to how to use it for a class method, and using signals using instance methods is pretty similar.
class MyClass(models.Model) test_field = models.Charfield(max_length=100) def __init__(self, *args, **kwargs): super(MyClass, self).__init__(*args, **kwargs) pre_save.connect(self.before_save, sender=MyClass) def before_save(self, sender, instance, *args, **kwargs): self.test_field = "It worked"
I'm not sure if this is a good idea or not, but it was useful when I needed an instance method called by an object of class A before saving class B.
Bwstearns
source share