Django signals using decorators

I have the following structure in my project


class Student():
    number = models.PositiveIntegerNumber(unique=True)
    name = models.CharField(max_length=64)

def post_delete:
    """some code"""

def post_save:
    """some code"""

class Course(SomeBaseModel):
    code = models.CharField(unique=True)
    teacher = models.CharField(max_length=64)



has functions post_delete

and post_save

defined in it.

def register(cls_object):
    @receiver(post_save, sender=cls_object.__name__)
    @receiver(post_delete, sender=cls_object.__name__)
    def _handler(sender, **kwargs):
        print 'inside _handler'

post_save.connect(_handler, sender=cls_object.__name__)
post_delete.connect(_handler, sender=cls_object.__name__)
return cls_object



fails when I remove any of the models. What am I missing?


source to share

All Articles