Django show object count on admin interface -
i have modified dashboard of dashboard.py file. there in have added custom module/widget called 'my widget' (haven't created myself rather appended child referring specific django app). code follows:
# append app list module "administration" self.children.append(modules.applist( _('administration'), models=('django.contrib.*',), )) self.children.append(modules.applist( _('my widget'), models=('flights.*',), children=[ ] ))
flights django app has 3 models. dashboard looks following:
on widget want show count of users did log in today. count able (not on admin interface through view accessible via url testing purpose) following code snippet: user.objects.filter(last_login__startswith=timezone.now().date()).count()
how can show such count on widget?
the entire dashboard.py:
""" file generated customdashboard management command, contains 2 classes main dashboard , app index dashboard. can customize these classes want. activate index dashboard add following settings.py:: admin_tools_index_dashboard = 'api.dashboard.customindexdashboard' , activate app index dashboard:: admin_tools_app_index_dashboard = 'api.dashboard.customappindexdashboard' """ django.utils.translation import ugettext_lazy _ django.core.urlresolvers import reverse admin_tools.dashboard import modules, dashboard, appindexdashboard admin_tools.utils import get_admin_site_name admin_tools_stats.modules import dashboardcharts, get_active_graph class customindexdashboard(dashboard): """ custom index dashboard api. """ columns = 3 def init_with_context(self, context): site_name = get_admin_site_name(context) # append link list module "quick links" self.children.append(modules.linklist( _('quick links'), layout='inline', draggable=false, deletable=false, collapsible=false, children=[ [_('return site'), '/'], [_('change password'), reverse('%s:password_change' % site_name)], [_('log out'), reverse('%s:logout' % site_name)], ] )) graph_list = get_active_graph() in graph_list: kwargs = {} kwargs['require_chart_jscss'] = true kwargs['graph_key'] = i.graph_key if context['request'].post.get('select_box_' + i.graph_key): kwargs['select_box_' + i.graph_key] = context['request'].post['select_box_' + i.graph_key] self.children.append(dashboardcharts(**kwargs)) # append app list module "applications" self.children.append(modules.applist( _('all applications'), exclude=('django.contrib.*',), )) # append app list module self.children.append(modules.applist( _('dashboard stats settings'), models=('admin_tools_stats.*', ), )) # append app list module "administration" self.children.append(modules.applist( _('administration'), models=('django.contrib.*',), )) self.children.append(modules.applist( _('my widget'), models=('flights.*',), content='test content', children=[ ] )) # append recent actions module self.children.append(modules.recentactions(_('recent actions'), 4)) # append link list module "support". self.children.append(modules.linklist( _('support'), children=[ { 'title': _('django documentation'), 'url': 'http://docs.djangoproject.com/', 'external': true, }, { 'title': _('django "django-users" mailing list'), 'url': 'http://groups.google.com/group/django-users', 'external': true, }, { 'title': _('django irc channel'), 'url': 'irc://irc.freenode.net/django', 'external': true, }, ] )) class customappindexdashboard(appindexdashboard): """ custom app index dashboard api. """ # disable title because redundant model list module title = '' def __init__(self, *args, **kwargs): appindexdashboard.__init__(self, *args, **kwargs) # append model list module , recent actions module self.children += [ modules.modellist(self.app_title, self.models), modules.recentactions( _('recent actions'), include_list=self.get_app_content_types(), limit=5 ) ] def init_with_context(self, context): """ use method if need access request context. """ return super(customappindexdashboard, self).init_with_context(context)