How to add custom view to custom AdminSite in Django

im a beginner with Django and basically want to add a section in Django Admin where if I click on it, I have a view that can process data.

For example: I have models Campaign and Components which I can access through Django Admin and now I also want an Option "Analytics" that work the same way as if it was a model. Maybe this image will make clear what I want: Django should look like this

When I click on "Analytics" I want to call a view that can fill a html template with data that I calculate from my models e.g. build a table that counts my instances of Campaigns and Components.

What I've done so far: create a custom AdminSite to overwrite the default AdminSite. Problem: I do not see my option appearing.

#admin.py
class MyAdminSite(admin.AdminSite):
    def get_urls(self):
        urls = super(MyAdminSite, self).get_urls()
        custom_urls = [
            path(r'myapi/test/', self.admin_view(testview)),
        ]
        return urls + custom_urls

    site_header = "My custom site"

admin_site = MyAdminSite(name="myadmin")
#apps.py
class MyAdminConfig(AdminConfig):
    default_site = "myapi.admin.MyAdminSite"
#settings.py
INSTALLED_APPS = [
    'rest_framework',
    #'django.contrib.admin',
    "myapi.apps.MyAdminConfig",
#views.py
@api_view(["GET", "POST"])
def testview(request):
    print("testmyview")
    return render(1, "mytest.html")
#urls.py
urlpatterns = [
    path('admin/', admin_site.urls),
    path('api/', include('myapi.urls')),
]

I tried to follow this tutorial: https://adriennedomingus.medium.com/adding-custom-views-or-templates-to-django-admin-740640cc6d42 but I think after overwriting the get_urls() I should see a new option appearing on my Django Admin, which is not the case.

Back to Top