-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Demonstrate adding a custom tabbed view to a core model (v3.4) #23
Comments
Hi! I am trying to use this feature but I can't get it to work. What I want to do is adding a tab on tenants that lists (with a table I created) some related objects. I tried something like this (in from tenancy.models import Tenant
from netbox.views import generic
from . import models, tables
from utilities.views import ViewTab, register_model_view
@register_model_view(Tenant, name='myview', path='some-other-stuff')
class MyView(generic.ObjectListView):
queryset = models.PluginObject.objects.all()
table = tables.PluginObjectTable
tab = ViewTab(
label='Other Stuff',
badge=lambda obj: obj.stuff_related_name.count(),
permission='myplugin.view_stuff'
) The tab does render with the correct count badge but I get an Thanks to anybody that could help me 😄 EDIT: I finally got this to work by looking into the netbox code / other plugins code. Here is my view: @register_model_view(Tenant, name='myview', path='some-other-stuff')
class MyView(generic.ObjectChildrenView):
queryset = Tenant.objects.all().prefetch_related('stuff_set')
child_model = models.Stuff
table = tables.StuffTable
template_name = "myplugin/stuffchild.html"
hide_if_empty = True
tab = ViewTab(
label='My Custom View',
badge=lambda obj: obj.stuff_set.count(),
permission='myplugin.view_stuff'
)
def get_children(self, request, parent):
return parent.stuff_set.all() and I added the following in {% extends 'generic/object.html' %}
{% load render_table from django_tables2 %}
{% block content %}
<div class="card">
<div class="card-body" id="object_list">
{% render_table table %}
</div>
</div>
{% endblock content%} I don't know if this is the right way to do but it works fine for me 😄 |
Had the same issue, but wanted to comment, that one can use the generic template |
NetBox v3.4 introduced the ability for plugins to register custom views that appear as tabs on core model views (FR #9072).
The text was updated successfully, but these errors were encountered: