0

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
Kheshav Sewnundun
  • 1,236
  • 15
  • 37
  • What specifically have tried from the answers in the post that you linked to, and what didn't work? Your question seems to be identical to that one. – solarissmoke Nov 04 '17 at 10:00
  • You are finding [How to arguments django signals - post_save/pre_save](https://stackoverflow.com/a/23452387/6360580). This answer is maybe what you need. – Huu-Danh Pham Nov 04 '17 at 10:11

0 Answers0