I'm having trouble accessing the created
argument, from my post_save
signal receiver.
@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()
When I call save()
on a Facility
instance, I receive the following error:
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