Closed TristanBrotherton closed 11 months ago
did u found a solution ?
@Cacsjep did you found a solution?
I dont use Django anymore because some very dynamic out of Standart stuff things are always a mess if Django not your day to day Business
In case others looking for a solution without registering a model:
# views.py
class SampleClassBasedView(UnfoldAdminViewMixin, TemplateView):
title = "Custom Title" # required: custom page header title
permissions_required = () # required: tuple of permissions
template_name = "admin/sample.html"
def has_permission(self):
return self.request.user.is_superuser
where the UnfoldAdminViewMixin
# mixins.py
from typing import Any, Dict
from django.contrib import admin
from django.contrib.auth.mixins import PermissionRequiredMixin
from unfold.exceptions import UnfoldException
class UnfoldAdminViewMixin(PermissionRequiredMixin):
"""
Prepares views to be displayed in admin
"""
def __init__(self, **kwargs):
super().__init__(**kwargs)
def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:
if not hasattr(self, "title"):
raise UnfoldException(
"UnfoldModelAdminViewMixin was not provided with 'title' attribute"
)
return super().get_context_data(
**kwargs,
**admin.site.each_context(self.request),
**{"title": self.title},
)
@lukasvinclav If you are open to it, I can create a PR and add some doc. I saw more issues related to this.
In the demo there is a navigation component that shows "analytics" as an example. Is there any documentation on how to add an additional page in the admin interface such as this analytics page - and be linked by the navigation component and render the rest of the unfold UI as the index.html page does?
If i create a new view, and render a new page
and that page contains:
The rendered page doesn't contain any of the unfold UI I presume as it wasn't provided required context. Additionally I'm also unsure how to provide the link of this page to the navigation component.