mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Closes #9887: Inspect docs_url property to determine link to model documentation
This commit is contained in:
@ -49,6 +49,12 @@ class MyModel(NetBoxModel):
|
||||
...
|
||||
```
|
||||
|
||||
### NetBoxModel Properties
|
||||
|
||||
#### `docs_url`
|
||||
|
||||
This attribute specifies the URL at which the documentation for this model can be reached. By default, it will return `/static/docs/models/<app_label>/<model_name>/`. Plugin models can override this to return a custom URL. For example, you might direct the user to your plugin's documentation hosted on [ReadTheDocs](https://readthedocs.org/).
|
||||
|
||||
### Enabling Features Individually
|
||||
|
||||
If you prefer instead to enable only a subset of these features for a plugin model, NetBox provides a discrete "mix-in" class for each feature. You can subclass each of these individually when defining your model. (Your model will also need to inherit from Django's built-in `Model` class.)
|
||||
|
@ -40,6 +40,7 @@ A new `PluginMenu` class has been introduced, which enables a plugin to inject a
|
||||
* [#9071](https://github.com/netbox-community/netbox/issues/9071) - Introduce `PluginMenu` for top-level plugin navigation menus
|
||||
* [#9072](https://github.com/netbox-community/netbox/issues/9072) - Enable registration of tabbed plugin views for core NetBox models
|
||||
* [#9880](https://github.com/netbox-community/netbox/issues/9880) - Introduce `django_apps` plugin configuration parameter
|
||||
* [#9887](https://github.com/netbox-community/netbox/issues/9887) - Inspect `docs_url` property to determine link to model documentation
|
||||
* [#10314](https://github.com/netbox-community/netbox/issues/10314) - Move `clone()` method from NetBoxModel to CloningMixin
|
||||
* [#10739](https://github.com/netbox-community/netbox/issues/10739) - Introduce `get_queryset()` method on generic views
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
from django.conf import settings
|
||||
from django.core.validators import ValidationError
|
||||
from django.db import models
|
||||
from mptt.models import MPTTModel, TreeForeignKey
|
||||
@ -26,6 +27,10 @@ class NetBoxFeatureSet(
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
@property
|
||||
def docs_url(self):
|
||||
return f'{settings.STATIC_URL}docs/models/{self._meta.app_label}/{self._meta.model_name}/'
|
||||
|
||||
@classmethod
|
||||
def get_prerequisite_models(cls):
|
||||
"""
|
||||
|
@ -37,9 +37,9 @@ Context:
|
||||
{% endif %}
|
||||
|
||||
{# Link to model documentation #}
|
||||
{% if object and settings.DOCS_ROOT %}
|
||||
{% if settings.DOCS_ROOT and object.docs_url %}
|
||||
<div class="float-end">
|
||||
<a href="{{ object|get_docs_url }}" target="_blank" class="btn btn-sm btn-outline-secondary" title="View model documentation">
|
||||
<a href="{{ object.docs_url }}" target="_blank" class="btn btn-sm btn-outline-secondary" title="View model documentation">
|
||||
<i class="mdi mdi-help-circle"></i> Help
|
||||
</a>
|
||||
</div>
|
||||
|
@ -141,14 +141,6 @@ def percentage(x, y):
|
||||
return round(x / y * 100)
|
||||
|
||||
|
||||
@register.filter()
|
||||
def get_docs_url(model):
|
||||
"""
|
||||
Return the documentation URL for the specified model.
|
||||
"""
|
||||
return f'{settings.STATIC_URL}docs/models/{model._meta.app_label}/{model._meta.model_name}/'
|
||||
|
||||
|
||||
@register.filter()
|
||||
def has_perms(user, permissions_list):
|
||||
"""
|
||||
|
Reference in New Issue
Block a user