From 4284028bb0621be47c1bb7e23a99ba58c2d498b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markku=20Leini=C3=B6?= Date: Tue, 16 Apr 2024 11:08:13 +0300 Subject: [PATCH] Closes #15727: Add tab template context variable in the plugin doc --- docs/plugins/development/views.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/plugins/development/views.md b/docs/plugins/development/views.md index 1730b0ebd..3c13a6fcb 100644 --- a/docs/plugins/development/views.md +++ b/docs/plugins/development/views.md @@ -157,7 +157,7 @@ These views are provided to enable or enhance certain NetBox model features, suc ### Additional Tabs -Plugins can "attach" a custom view to a core NetBox model by registering it with `register_model_view()`. To include a tab for this view within the NetBox UI, declare a TabView instance named `tab`: +Plugins can "attach" a custom view to a core NetBox model by registering it with `register_model_view()`. To include a tab for this view within the NetBox UI, declare a TabView instance named `tab`, and add it to the template context dict: ```python from dcim.models import Site @@ -173,6 +173,16 @@ class MyView(generic.ObjectView): badge=lambda obj: Stuff.objects.filter(site=obj).count(), permission='myplugin.view_stuff' ) + + def get(self, request, pk): + ... + return render( + request, + "myplugin/mytabview.html", + context={ + "tab": self.tab, + }, + ) ``` ::: utilities.views.register_model_view