寫了Excel格式的HTML標準來表示日期明智計數如何在HTML的Django aggreate
def get_detail(usr,dt):
res = Dataset.objects.filter(user = usr, date = dt).values('expense')
try :
output=res[0]['expense']
except IndexError:
output=" "
return output
上面的代碼是
def metrics_new(request, year = None, month = None):
import calendar
from datetime import *
from dateutil.relativedelta import relativedelta
m = Profile.objects.filter(lead = 'sushanth' ,status='A')
now=datetime.today()
if not year:
year = now.year
if not month:
month = now.month
year = int(year)
month = int(month)
d = calendar.mdays[month]
out_txt="<TABLE id=\"myTable\" class=\"tablesorter\">\n"
out_txt += "<THEAD>"
out_txt += "<TR>"
out_txt += "<TH> LDAP </TH>"
for i in xrange(1,d):
date_format = now.replace(year = year , month = month , day = i)
out_txt += "<TH>" + str(date_format) + "</TH>"
out_txt += "</TR>\n"
out_txt += "</THEAD>"
s_no = 0
for fetch in m:
out_txt += "<TR>"
ld = fetch.user
out_txt += "<TD>" + str(ld) + "</TD>"
for i in xrange(1,d):
date_format = now.replace(year = year , month = month , day = i)
out_txt += "<TD>" + str(get_details(ld,date_format)) + "</TD>"
out_txt += "<TR>\n"
out_txt +="</TABLE>\n"
try:
cal_date = date(int(year), int(month), 1)
except ValueError:
raise Http404
prev_month = (cal_date + relativedelta(months = -1))
next_month = (cal_date + relativedelta(months = +1))
return render_to_response('metrics.html', {'table':out_txt,
'prev_month':prev_month,'next_month': next_month, },
context_instance = RequestContext(request))
我已經生成的表和它的工作,怎一個功能聚集費用在每行
輸出:
user 2011-02-01 2011-02-02 2011-02-03 2011-02-04.......2011-02-28
x 2 4 5 2
y 1 2
z 4
,但我想在下面的格式
user 2011-02-01 2011-02-02 2011-02-03 2011-02-04.......2011-02-28 total
x 2 4 5 2 13
y 1 2 3
z 4 4
在這裏,我想在 年底彙總的數據呢?
有沒有什麼最好的方法可以做到這一點?
在此先感謝
唉,不要在您的視圖中手動創建HTML。有一個完整的模板語言。 – 2011-03-07 18:24:47
@ daniel,我嘗試了很多方法,但最後我手動創建了HTML,你能否給我建議一些代碼示例? – sush 2011-03-08 01:24:45