from django.contrib.admin import ModelAdmin from datetime.datetime import now class ProfileAdmin(ModelAdmin): list_display = ('votes_today',) def votes_today(self, obj): today = now().replace(hour=0, minute=0, second=0, microsecond=0) return obj.vote_set.filter(created__gte=today) votes_today.short_description = lambda: 'Votes today (%s)' % now().strftime('%B %d') # Doesn't work, callables not supported #---------------------------------------------------------# from django.contrib.admin import ModelAdmin from datetime.datetime import now class ProfileAdmin(ModelAdmin): list_display = ('votes_today',) class VotesToday: def __call__(self, model_admin, obj): today = now().replace(hour=0, minute=0, second=0, microsecond=0) return obj.vote_set.filter(created__gte=today) @property def short_description(self): return 'Votes today (%s)' % now().strftime('%B %d') @property def votes_today(self): if not hasattr(self, '__votes_today'): self.__votes_today = self.VotesToday() return self.__votes_today