Skip to content

Update docs: How to easily create custom template views in adminsite #1239

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/sites/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,27 @@ from django.contrib.admin.apps import AdminConfig
class MyAdminConfig(AdminConfig):
default_site = "myproject.sites.CustomAdminSite"
```

## Non-model based views in admin site:

```python
from django.shortcuts import render
from django.urls import path
from unfold.sites import UnfoldAdminSite

class MyAdminSite(UnfoldAdminSite):
def get_urls(self):
urls = super().get_urls()
urls += [
path('my_custom_view/', self.admin_view(self.my_custom_view), name='my_custom_view'),
]
return urls

def my_custom_view(self, request):
template = 'admin/my-custom-view-template.html'
context = self.each_context(request)
# Use the context in your view logic or template rendering
return render(request, template, context)

admin_site = MyAdminSite()
```