|
@@ -304,6 +304,13 @@ class CustomFieldChoice(models.Model):
|
|
|
# Custom links
|
|
# Custom links
|
|
|
#
|
|
#
|
|
|
|
|
|
|
|
|
|
+def get_custom_link_models():
|
|
|
|
|
+ # TODO: This should match on the app_label as well as the model name to avoid potential duplicate names
|
|
|
|
|
+ return {
|
|
|
|
|
+ 'model__in': [model.split('.')[1] for model in CUSTOM_LINK_MODELS],
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
class CustomLink(models.Model):
|
|
class CustomLink(models.Model):
|
|
|
"""
|
|
"""
|
|
|
A custom link to an external representation of a NetBox object. The link text and URL fields accept Jinja2 template
|
|
A custom link to an external representation of a NetBox object. The link text and URL fields accept Jinja2 template
|
|
@@ -311,7 +318,8 @@ class CustomLink(models.Model):
|
|
|
"""
|
|
"""
|
|
|
content_type = models.ForeignKey(
|
|
content_type = models.ForeignKey(
|
|
|
to=ContentType,
|
|
to=ContentType,
|
|
|
- on_delete=models.CASCADE
|
|
|
|
|
|
|
+ on_delete=models.CASCADE,
|
|
|
|
|
+ limit_choices_to=get_custom_link_models
|
|
|
)
|
|
)
|
|
|
name = models.CharField(
|
|
name = models.CharField(
|
|
|
max_length=100,
|
|
max_length=100,
|
|
@@ -319,22 +327,26 @@ class CustomLink(models.Model):
|
|
|
)
|
|
)
|
|
|
text = models.CharField(
|
|
text = models.CharField(
|
|
|
max_length=200,
|
|
max_length=200,
|
|
|
- help_text="Template code for link text"
|
|
|
|
|
|
|
+ help_text="Jinja2 template code for link text"
|
|
|
)
|
|
)
|
|
|
url = models.CharField(
|
|
url = models.CharField(
|
|
|
max_length=200,
|
|
max_length=200,
|
|
|
- help_text="Template code for link URL"
|
|
|
|
|
|
|
+ verbose_name='URL',
|
|
|
|
|
+ help_text="Jinja2 template code for link URL"
|
|
|
)
|
|
)
|
|
|
weight = models.PositiveSmallIntegerField(
|
|
weight = models.PositiveSmallIntegerField(
|
|
|
default=100
|
|
default=100
|
|
|
)
|
|
)
|
|
|
group_name = models.CharField(
|
|
group_name = models.CharField(
|
|
|
max_length=50,
|
|
max_length=50,
|
|
|
- blank=True
|
|
|
|
|
|
|
+ blank=True,
|
|
|
|
|
+ help_text="Links with the same group will appear as a dropdown menu"
|
|
|
)
|
|
)
|
|
|
button_class = models.CharField(
|
|
button_class = models.CharField(
|
|
|
max_length=30,
|
|
max_length=30,
|
|
|
- choices=BUTTON_CLASS_CHOICES
|
|
|
|
|
|
|
+ choices=BUTTON_CLASS_CHOICES,
|
|
|
|
|
+ default=BUTTON_CLASS_DEFAULT,
|
|
|
|
|
+ help_text="The class of the first link in a group will be used for the dropdown button"
|
|
|
)
|
|
)
|
|
|
new_window = models.BooleanField(
|
|
new_window = models.BooleanField(
|
|
|
help_text="Force link to open in a new window"
|
|
help_text="Force link to open in a new window"
|