TypeError: connect() got an unexpected keyword argument 'signal' - Django signals -


i'm trying create simple signal prints after new object of staff model saved in django-admin. mvc python files live in appname. here code in each file:

models.py

from django.db import models django.db.models import signals django.dispatch import signal django.contrib.auth.models import user appname.signals import printfunction django.db.models.signals import post_save   class staff(user):     class meta:         proxy = true         app_label = 'auth'         verbose_name_plural = 'users - staff'  signal.connect(printfunction, signal=signals.post_save, sender=staff) 

signals.py

def printfunction(sender, instance, signal, *args, **kwargs):     print ("signal alpha!") 

however raising following exception: typeerror: connect() got unexpected keyword argument 'signal'

i followed 1.8 django documentation on signals. why error occurring , how fix it?

signal.connect(receiver[, sender=none, weak=true, dispatch_uid=none]) 

this common notation documentation. not literal code can used as-is. arguments in between [ , ] optional, if leave them out use default values. connect method on class signal. unless otherwise specified, can assume instance method. instead of literally calling signal.connect(), should call signal_instance.connect(), signal_instance of course instance of signal class.

in case, signals.post_save instance of signal, , it's instance want connect function. receiver argument required, , in case function printfunction. sender, weak , dispatch_uid optional. in example you're passing in staff sender, , leave other arguments default values. so, final function call should this:

signals.post_save.connect(printfunction, sender=staff) 

Comments