I am trying to use the ID of the django user for an action when a model is saved.
For that I have a receiver as follows:
@receiver(post_save, sender=ServersModel)
def create_zabbix_host(sender, instance=None, created=False, **kwargs):
if created:
print(instance.name)
print(kwargs)
I can get the ServersModel
name but I am unable to get the ID of the User am connected with.
Is there a way to get the connected user id in the ServersModel
receiver?
I have tried the following solutions but in vain: Get current user log in signal in Django
Part I tried as solution: But the request is always None
@receiver(post_save, sender=ServersModel)
def create_zabbix_host(sender, instance=None, created=False, **kwargs):
import inspect
for frame_record in inspect.stack():
if frame_record[3]=='get_response':
request = frame_record[0].f_locals['request']
break
else:
request = None