Add django signals functionality to Plugins #7112

Closed
opened 2025-12-29 20:19:22 +01:00 by adam · 2 comments
Owner

Originally created by @Selfmade-RuLeZ on GitHub (Oct 15, 2022).

NetBox version

v3.3.5

Feature type

New functionality

Proposed functionality

Currently a developer has to copy the ready(self) function from PluginConfig to get signals running.
Developers should be able to use signals just out of the box with a signals.py file in the root of the plugin directory.

I tried to implement it myself and I will create a pull request as it's just two/three lines in __init__.py from extras.plugins.

from importlib import import_module

...

class PluginConfig(AppConfig):

...

    signals = 'signals'

    def ready(self):
        plugin_name = self.name.rsplit('.', 1)[-1]

        # import signals if defined
        import_module(f"{self.__module__}.{self.signals}")

...

Use case

Plugins could react to actions from the main part of NetBox.

Example:
Someone develops a YubiKey plugin and wants to associate a new YubiKey everytime someone adds a new Device.
This could be reached super handy by signals in django.

Database changes

No response

External dependencies

No response

Originally created by @Selfmade-RuLeZ on GitHub (Oct 15, 2022). ### NetBox version v3.3.5 ### Feature type New functionality ### Proposed functionality Currently a developer has to copy the `ready(self)` function from `PluginConfig` to get signals running. Developers should be able to use signals just out of the box with a `signals.py` file in the root of the plugin directory. I tried to implement it myself and I will create a pull request as it's just two/three lines in `__init__.py` from `extras.plugins`. ``` from importlib import import_module ... class PluginConfig(AppConfig): ... signals = 'signals' def ready(self): plugin_name = self.name.rsplit('.', 1)[-1] # import signals if defined import_module(f"{self.__module__}.{self.signals}") ... ``` ### Use case Plugins could react to actions from the main part of NetBox. Example: Someone develops a YubiKey plugin and wants to associate a new YubiKey everytime someone adds a new Device. This could be reached super handy by signals in django. ### Database changes _No response_ ### External dependencies _No response_
adam added the type: feature label 2025-12-29 20:19:22 +01:00
adam closed this issue 2025-12-29 20:19:23 +01:00
Author
Owner

@DanSheps commented on GitHub (Oct 18, 2022):

Currently a developer has to copy the ready(self) function from PluginConfig to get signals running.

def ready(self):
    super().ready()
    import_module(f"{self.__module__}.{self.signals}")
@DanSheps commented on GitHub (Oct 18, 2022): > Currently a developer has to copy the ready(self) function from PluginConfig to get signals running. ``` def ready(self): super().ready() import_module(f"{self.__module__}.{self.signals}") ```
Author
Owner

@Selfmade-RuLeZ commented on GitHub (Oct 18, 2022):

Oh, my fault. Sorry about that, was too late on this day and my last python project with inheritance was some time ago.

But to be honest, it would be more convenient in combination with the current documentation, that the Plugin imports the signal by itself the same way it does with the menu items.

I close this as the main purpose of this issue was solved. Thank you @DanSheps 😀

@Selfmade-RuLeZ commented on GitHub (Oct 18, 2022): Oh, my fault. Sorry about that, was too late on this day and my last python project with inheritance was some time ago. But to be honest, it would be more convenient in combination with the current documentation, that the Plugin imports the signal by itself the same way it does with the menu items. I close this as the main purpose of this issue was solved. Thank you @DanSheps 😀
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7112