Model Inheritance - And Signals

705 views
Skip to first unread message

Vitaly Babiy

unread,
Nov 7, 2008, 12:03:48 PM11/7/08
to django...@googlegroups.com
if I define a model called CustomModel and I attach attach a pre_save signal to it. Is there any way to have that signal be called any time model that extends CustomModel is being saved has that method saved.

I know i could do this by overriding the save method on CustomeModel but I was wondering if there is any way to do it with signals.

Thanks,
Vitaly Babiy

Alex Koshelev

unread,
Nov 7, 2008, 12:19:10 PM11/7/08
to django...@googlegroups.com
Try to connection handler without `sender` specified. And filter needed models inside it.

def my_handler(sender, **kwargs):
    if not isinstance(sender, CustomModel):
       return

signals.pre_save.connect(my_handler)

Vitaly Babiy

unread,
Nov 7, 2008, 12:50:47 PM11/7/08
to django...@googlegroups.com
Thanks Alex that worked great.
Vitaly Babiy
Reply all
Reply to author
Forward
0 new messages