Django admin interface to display aggregates -


i want use django admin interface display aggregates of data in model. ex: model has following fields [employee name, salary, month] want aggregate table fields [month, total_salary_paid, cumulative_of_month_salaries_paid]. how do ?? have searched internet didn't find way it..any reference or guidance help

here's snippet recent project of mine. adds column in admin "are there entries in m2m related table?" , "what's count of entries in m2m related table?". similar things other aggregate functions django offers.

from django.db.models import count django.contrib import admin  class expertmodeladmin(admin.modeladmin):     def num_companies(self, obj):         """# of companies expert has."""          return obj.num_companies     num_companies.short_description = "# companies"      def has_video(self, obj):         """does expert have video?"""          return bool(obj.has_video)     has_video.short_description = "video?"     has_video.boolean = true      def get_queryset(self, request):         """use can annotate additional info."""          qs = super(expertmodeladmin, self).get_queryset(request)         return qs.annotate(num_companies=count('company', distinct=true),                            has_video=count('mediaversion', distinct=true)) 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -