On other day, i struggle with django. WOW. I need a quick dashboard not all that apps lists. I usually use django-suit for my projects and that's really awesome. So make a new administration, no. The main admin do at i need but i want only a custom dashboard. Apply some freak apps to modify my main dashboard, nope i want total control to insert i want. So after many patch, try, error, do it something to it. What i'be done was simple subclass AdminSite an override the get_urls and put my custom index view on it.
So created a app called plus. In there a inserted two files, sites.py and views.py. On sites did this:
#sites.py from django.contrib.admin.sites import AdminSite class AdminMixin(object): """Mixin for AdminSite to allow custom dashboard views.""" def __init__(self, *args, **kwargs): return super(AdminMixin, self).__init__(*args, **kwargs) def get_urls(self): """Add our dashboard view to the admin urlconf. Deleted the default index.""" from django.conf.urls import patterns, url from views import DashboardWelcomeView urls = super(AdminMixin, self).get_urls() del urls custom_url = patterns('', url(r'^$', self.admin_view(DashboardWelcomeView.as_view()), name="index") ) return custom_url + urls class SitePlus(AdminMixin, AdminSite): """ A Django AdminSite with the AdminMixin to allow registering custom dashboard view. """
#views.py from django.views.generic import TemplateView class DashboardWelcomeView(TemplateView): template_name = 'admin/dashboard/welcome.html' def get(self, request, *args, **kwargs): context = self.get_context_data(**kwargs) return self.render_to_response(context=context)
Now our class for override on urls are ready. Let's make it happen.
#urls.py from django.contrib import admin from websublime.contrib.manager.plus.sites import SitePlus admin.site = SitePlus() admin.autodiscover() urlpatterns = patterns('', url(r'^admin/', include(admin.site.urls)), )
Admin site takes our new class to resolve our custom view. I made a TemplateView but it's up to you if you want on self index() or a custom view.
So, where it is my new dashboard view. As i said, if you use django-suit for template you will have a menu on left for your application and now a custom space for you dashboard. And that's it.