Allow Plugins to register a list of Django apps to be appended to INSTALLED_APPS #6739

Closed
opened 2025-12-29 19:44:51 +01:00 by adam · 6 comments
Owner

Originally created by @jsenecal on GitHub (Jul 29, 2022).

Originally assigned to: @jsenecal on GitHub.

NetBox version

v3.4

Feature type

New functionality

Proposed functionality

As discussed in https://github.com/netbox-community/netbox/issues/5086 (closed due to inactivity) it would be nice to allow for a plugin to append third-party Django Application into INSTALLED_APPS.

Borrowing from the issue above, the proposal is to extend the PluginConfig class to support a new django_apps attribute which would get appended to INSTALLED_APPS.

from extras.plugins import PluginConfig

class FooBarConfig(PluginConfig):
    name = 'foo_bar'
    verbose_name = 'Foo Bar'
    description = 'An example NetBox plugin'
    version = '0.1'
    author = 'Jeremy Stretch'
    author_email = 'author@example.com'
    base_url = 'foo-bar'
    required_settings = []
    default_settings = {
        'baz': True
    }
    django_apps = ["foo", "bar", "baz"] ### <<< HERE

config = FooBarConfig

These new apps should be inserted before the plugin that requires it, but after existing "core" apps in order to avoid conflicts.

The documentation should point out that additional apps may cause more harm than good and could lead to make identifying problems within NetBox itself more difficult or even cause problems. (But isn't that the case for every python package?)

Use case

When working with plugins, reusing third party libraries is a must to promote code re-use and allow for better functionality and ease of use.
Examples of that are apps that introduce new field types (with template tags), new templates, new models with migrations, new manage.py admin commands, etc. Most of the time, simply installing the python package for the additional app is simply not enough.

There are many existing Django apps that could be easily reused/extended within NetBox if we could seamlessly install them from a plugin.

Database changes

None within NetBox

External dependencies

None within NetBox

Originally created by @jsenecal on GitHub (Jul 29, 2022). Originally assigned to: @jsenecal on GitHub. ### NetBox version v3.4 ### Feature type New functionality ### Proposed functionality As discussed in https://github.com/netbox-community/netbox/issues/5086 (closed due to inactivity) it would be nice to allow for a plugin to append third-party Django Application into `INSTALLED_APPS`. Borrowing from the issue above, the proposal is to extend the `PluginConfig` class to support a new `django_apps` attribute which would get appended to `INSTALLED_APPS`. ```python from extras.plugins import PluginConfig class FooBarConfig(PluginConfig): name = 'foo_bar' verbose_name = 'Foo Bar' description = 'An example NetBox plugin' version = '0.1' author = 'Jeremy Stretch' author_email = 'author@example.com' base_url = 'foo-bar' required_settings = [] default_settings = { 'baz': True } django_apps = ["foo", "bar", "baz"] ### <<< HERE config = FooBarConfig ``` These new apps should be inserted before the plugin that requires it, but after existing "core" apps in order to avoid conflicts. The documentation should point out that additional apps may cause more harm than good and could lead to make identifying problems within NetBox itself more difficult or even cause problems. (But isn't that the case for every python package?) ### Use case When working with plugins, reusing third party libraries is a must to promote code re-use and allow for better functionality and ease of use. Examples of that are apps that introduce new field types (with template tags), new templates, new models with migrations, new `manage.py` admin commands, etc. Most of the time, simply installing the python package for the additional app is simply not enough. There are many existing Django apps that could be easily reused/extended within NetBox if we could seamlessly install them from a plugin. ### Database changes None within NetBox ### External dependencies None within NetBox
adam added the status: acceptedtype: featuretopic: plugins labels 2025-12-29 19:44:51 +01:00
adam closed this issue 2025-12-29 19:44:51 +01:00
Author
Owner

@jsenecal commented on GitHub (Jul 29, 2022):

This can be assigned to me and I can work on a PR if accepted.

@jsenecal commented on GitHub (Jul 29, 2022): This can be assigned to me and I can work on a PR if accepted.
Author
Owner

@jeremystretch commented on GitHub (Aug 1, 2022):

One thing to consider is the order in which apps are loaded. I don't know if it's something we need to address for plugins, but this has come up in core development. For example, we have to list django_rq after our extras app to ensure that we can override one of the management commands it provides.

@jeremystretch commented on GitHub (Aug 1, 2022): One thing to consider is [the order in which apps are loaded](https://docs.djangoproject.com/en/4.0/ref/applications/#how-applications-are-loaded). I don't know if it's something we need to address for plugins, but this has come up in core development. For example, we have to list `django_rq` _after_ our `extras` app to ensure that we can override one of the management commands it provides.
Author
Owner

@jsenecal commented on GitHub (Aug 2, 2022):

One thing to consider is the order in which apps are loaded. I don't know if it's something we need to address for plugins, but this has come up in core development. For example, we have to list django_rq after our extras app to ensure that we can override one of the management commands it provides.

As mentioned in the Proposed functionality section above:

These new apps should be inserted before the plugin that requires it, but after existing "core" apps in order to avoid conflicts.

Are you requesting for the ability to do the opposite ?

@jsenecal commented on GitHub (Aug 2, 2022): > One thing to consider is [the order in which apps are loaded](https://docs.djangoproject.com/en/4.0/ref/applications/#how-applications-are-loaded). I don't know if it's something we need to address for plugins, but this has come up in core development. For example, we have to list `django_rq` _after_ our `extras` app to ensure that we can override one of the management commands it provides. As mentioned in the `Proposed functionality` section above: > These new apps should be inserted before the plugin that requires it, but after existing "core" apps in order to avoid conflicts. Are you requesting for the ability to do the opposite ?
Author
Owner

@jeremystretch commented on GitHub (Aug 2, 2022):

I'm pointing out that it needs to be considered because there are scenarios where it may be required, such as the example I cited.

@jeremystretch commented on GitHub (Aug 2, 2022): I'm pointing out that it needs to be considered because there are scenarios where it may be required, such as the example I cited.
Author
Owner

@jsenecal commented on GitHub (Aug 2, 2022):

In that case we may consider the order of the list django_apps as important when the plugin name itself is in the list.
like so:

django_apps = ["foo", "bar", "my_netbox_plugin", "baz"]

If "my_netbox_plugin" is not in the list, we append it to the end automatically for convenience.

This would in turn define the import order for the apps and plugin.

@jsenecal commented on GitHub (Aug 2, 2022): In that case we may consider the order of the list `django_apps` as important when the plugin name itself is in the list. like so: ```python django_apps = ["foo", "bar", "my_netbox_plugin", "baz"] ``` If `"my_netbox_plugin"` is not in the list, we append it to the end automatically for convenience. This would in turn define the import order for the apps and plugin.
Author
Owner

@jeremystretch commented on GitHub (Aug 30, 2022):

Thinking about this further, I can't come up with a scenario where you would need to load another Django app after a plugin which depends on it, so maybe it doesn't matter so long as the dependencies are loaded before all plugins.

@jeremystretch commented on GitHub (Aug 30, 2022): Thinking about this further, I can't come up with a scenario where you would need to load another Django app _after_ a plugin which depends on it, so maybe it doesn't matter so long as the dependencies are loaded before all plugins.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6739