Skip to content

Commit dac8d6b

Browse files
committed
Add last_execution field to ScriptInstanceTable
1 parent 1c645c9 commit dac8d6b

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

netbox_script_manager/models.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ def script(self):
225225

226226
return script_class()
227227

228+
@property
229+
def last_execution(self):
230+
return self.script_executions.order_by("-created").first()
231+
228232
class Meta:
229233
ordering = ("group", "weight", "name")
230234
indexes = [

netbox_script_manager/tables.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,34 @@ class ScriptInstanceTable(NetBoxTable):
1414
tenant = TenantColumn(
1515
verbose_name=_("Tenant"),
1616
)
17+
last_execution = tables.TemplateColumn(
18+
template_code="""
19+
{% if value %}
20+
{{ value.created }}
21+
{% else %}
22+
<span class="text-muted">Never</span>
23+
{% endif %}
24+
""",
25+
accessor="last_execution",
26+
linkify=lambda value: value.get_absolute_url() if value else None,
27+
)
1728

1829
class Meta(NetBoxTable.Meta):
1930
model = ScriptInstance
20-
fields = ("pk", "id", "name", "group", "weight", "description", "module_path", "class_name", "created", "last_updated", "tags")
31+
fields = (
32+
"pk",
33+
"id",
34+
"name",
35+
"group",
36+
"weight",
37+
"description",
38+
"module_path",
39+
"class_name",
40+
"created",
41+
"last_updated",
42+
"tags",
43+
"last_execution",
44+
)
2145
default_columns = ("group", "name", "description", "tags")
2246

2347

0 commit comments

Comments
 (0)