Django 1.2: How to connect pre_save signal to class method

前端 未结 3 652
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-12 11:34

I am trying to define a \"before_save\" method in certain classes in my django 1.2 project. I\'m having trouble connecting the signal to the class method in models.py.

3条回答
  •  旧时难觅i
    2021-01-12 12:36

    Rather than use a method on MyClass, you should just use a function. Something like:

    def before_save(sender, instance, *args, **kwargs):
        instance.test_field = "It worked"
    
    pre_save.connect(before_save, sender=MyClass)
    

提交回复
热议问题