我无法从我的created
信号接收器访问post_save
参数。
@receiver(post_save, sender=Facility)
def add_times(sender, **kwargs):
instance = kwargs.get('instance', None)
created = kwargs.get('created', False)
if isinstance(instance, Facility) and created:
instance.add_opening_times()
当我在save()
个实例上调用Facility
时,收到以下错误:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\bin\Python35\lib\site-packages\django\db\models\base.py", line 708, in save
force_update=force_update, update_fields=update_fields)
File "C:\bin\Python35\lib\site-packages\django\db\models\base.py", line 745, in save_base
update_fields=update_fields, raw=raw, using=using)
File "C:\bin\Python35\lib\site-packages\django\dispatch\dispatcher.py", line 192, in send
response = receiver(signal=self, sender=sender, **named)
File "C:\git\SimplySport\facility\models.py", line 53, in update_stock
instance = kwargs.get('instance', None)
NameError: name 'created' is not defined
https://docs.djangoproject.com/en/1.9/ref/signals/#post-save