1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Custom link cleanup

This commit is contained in:
Jeremy Stretch
2019-04-15 21:29:02 -04:00
parent 4536754b20
commit 2ec7ac1ea3
4 changed files with 57 additions and 7 deletions

View File

@@ -304,6 +304,13 @@ class CustomFieldChoice(models.Model):
# 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):
"""
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(
to=ContentType,
on_delete=models.CASCADE
on_delete=models.CASCADE,
limit_choices_to=get_custom_link_models
)
name = models.CharField(
max_length=100,
@@ -319,22 +327,26 @@ class CustomLink(models.Model):
)
text = models.CharField(
max_length=200,
help_text="Template code for link text"
help_text="Jinja2 template code for link text"
)
url = models.CharField(
max_length=200,
help_text="Template code for link URL"
verbose_name='URL',
help_text="Jinja2 template code for link URL"
)
weight = models.PositiveSmallIntegerField(
default=100
)
group_name = models.CharField(
max_length=50,
blank=True
blank=True,
help_text="Links with the same group will appear as a dropdown menu"
)
button_class = models.CharField(
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(
help_text="Force link to open in a new window"