-
|
Hi, I am currently writing a Plugin for Netbox where I implement my own model with corresponding CRUD views. I just cannot figure out how to add a tab to my detail view. I tried using I tried to overwrite the tab block It feels like there must be such a simple solution for this but I just cannot figure it out. Any help would be much appreciated! This is my current code, very much in the trial & error phase: Current Plugin View: class SystemTemplateView(generic.ObjectView):
queryset = models.SystemTemplate.objects.all()
@register_model_view(models.SystemTemplate, 'foo', path='foo')
class SystemTemplateSystemsView(generic.ObjectChildrenView):
queryset = models.SystemTemplate.objects.all()
child_model = models.System
table = tables.SystemTable
template_name = 'generic/object_children.html'
# filterset = filtersets.ConsolePortFilterSet
tab = ViewTab(
label='FooBar',
badge='0',
)
def get_children(self, request, parent):
return self.child_model.objects.filter(system_template=parent)Doing the same thing in core Netbox model ClusterType: @register_model_view(ClusterType, 'foo', path='foo')
class SystemTemplateSystemsView(generic.ObjectView):
queryset = models.SystemTemplate.objects.all()
child_model = models.System
table = tables.SystemTable
template_name = 'generic/object_children.html'
# filterset = filtersets.ConsolePortFilterSet
tab = ViewTab(
label='FooBar',
badge='0',
)I also added a url for the new tab path('system-templates/<int:pk>/systems', views.SystemTemplateSystemsView.as_view(), name='systemtemplate_systems')Navigating to this URL works as expected As you see it renders the correct content but no tab |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Ayy, I solved it myself I had to also add the @register_model_view(model=models.SystemTemplate) # <-- DECORATOR ALSO GOES HERE
class SystemTemplateView(generic.ObjectView):
queryset = models.SystemTemplate.objects.all()
@register_model_view(model=models.SystemTemplate, name='foo', path='foo', )
class SystemTemplateSystemsView(generic.ObjectChildrenView):
queryset = models.SystemTemplate.objects.all()
child_model = models.System
table = tables.SystemTable
template_name = 'generic/object_children.html'
# filterset = filtersets.ConsolePortFilterSet
tab = ViewTab(
label='FooBar',
badge='0',
)
def get_children(self, request, parent):
return self.child_model.objects.filter(system_template=parent) |
Beta Was this translation helpful? Give feedback.



Ayy, I solved it myself
I had to also add the
@register_model_view()decorator (without a path or name, just the model) to the base viewSystemTemplateView