44from xadmin .layout import Main , TabHolder , Tab , Fieldset , Row , Col , AppendedText , Side
55from xadmin .plugins .inline import Inline
66from xadmin .plugins .batch import BatchChangeAction
7+ from django .db .models import Avg , Max , Min , Count , Sum
78
89class MainDashboard (object ):
910 widgets = [
@@ -22,8 +23,8 @@ class MainDashboard(object):
2223
2324
2425class BaseSetting (object ):
25- enable_themes = True
26- use_bootswatch = True
26+ enable_themes = False
27+ use_bootswatch = False
2728xadmin .site .register (views .BaseAdminView , BaseSetting )
2829
2930
@@ -172,24 +173,39 @@ def avg_count(self, instance):
172173 avg_count .allow_tags = True
173174 avg_count .is_column = True
174175
175- list_display = ('date' , 'user_count' , 'view_count' , 'avg_count' )
176- list_display_links = ('date' ,)
176+ def user_count_sum (self , obj ):
177+ return obj
178+ user_count_sum .short_description = "User Count Sum"
177179
178- list_filter = ['date' , 'user_count' , 'view_count' ]
180+ def view_count_sum (self , obj ):
181+ return obj
182+ view_count_sum .short_description = "View Count Sum"
183+
184+ list_display = ('date' , 'user_count_sum' , 'view_count_sum' )
185+
186+ list_filter = ['date' ]
179187 actions = None
180- aggregate_fields = {"user_count" : "sum" , 'view_count' : "sum" }
181188
182- refresh_times = (3 , 5 , 10 )
183- data_charts = {
184- "user_count" : {'title' : u"User Report" , "x-field" : "date" , "y-field" : ("user_count" , "view_count" ), "order" : ('date' ,)},
185- "avg_count" : {'title' : u"Avg Report" , "x-field" : "date" , "y-field" : ('avg_count' ,), "order" : ('date' ,)},
186- "per_month" : {'title' : u"Monthly Users" , "x-field" : "_chart_month" , "y-field" : ("user_count" , ),
187- "option" : {
188- "series" : {"bars" : {"align" : "center" , "barWidth" : 0.8 ,'show' :True }},
189- "xaxis" : {"aggregate" : "sum" , "mode" : "categories" },
190- },
191- },
189+ pivot_fields = {
190+ 'values' : ['date' ,],
191+ 'annotate' : {
192+ 'user_count_sum' : Sum ('user_count' ),
193+ 'view_count_sum' : Sum ('view_count' ),
194+ }
192195 }
196+ # aggregate_fields = {"user_count": "sum", 'view_count': "sum"}
197+
198+ # refresh_times = (3, 5, 10)
199+ # data_charts = {
200+ # "user_count": {'title': u"User Report", "x-field": "date", "y-field": ("user_count", "view_count"), "order": ('date',)},
201+ # "avg_count": {'title': u"Avg Report", "x-field": "date", "y-field": ('avg_count',), "order": ('date',)},
202+ # "per_month": {'title': u"Monthly Users", "x-field": "_chart_month", "y-field": ("user_count", ),
203+ # "option": {
204+ # "series": {"bars": {"align": "center", "barWidth": 0.8,'show':True}},
205+ # "xaxis": {"aggregate": "sum", "mode": "categories"},
206+ # },
207+ # },
208+ # }
193209
194210 def _chart_month (self ,obj ):
195211 return obj .date .strftime ("%B" )
0 commit comments