python - Django 1.2: How to connect pre_save signal to class method -


i trying define "before_save" method in classes in django 1.2 project. i'm having trouble connecting signal class method in models.py.

class myclass(models.model):     ....     def before_save(self, sender, instance, *args, **kwargs):         self.test_field = "it worked" 

i've tried putting pre_save.connect(before_save, sender='self') in 'myclass' itself, nothing happens.

i've tried putting @ bottom of models.py file:

pre_save.connect(myclass.before_save, sender=myclass) 

i read connecting signals class methods here, can't figure out code.

anybody know i'm doing wrong?

rather use method on myclass, should use function. like:

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

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -