经过反复试验,我找到了答案!在我的示例中,我在一个名为“jd_gross”的查询集中有一个字段,我想在我的报告中对其进行总计......我最终放弃了 action=FIELD_ACTION_SUM 部分并推出了我自己的
在我的 band_detail 部分中,我可以用逗号显示此字段,其中包含以下内容:
ObjectValue(attribute_name='jd_gross', left=26.7*cm, width=1.7*cm, style={'alignment':TA_RIGHT}, get_value=lambda instance: intcomma(instance.jd_gross)),
但是,对摘要部分有用的答案是添加到 : def init (self, *args, **kwargs): 部分,在 : self.band_page_header.elements += [ 我使用相同的概念来计算我的总数,将其转换为格式化字符串,并将一行作为系统字段添加到我的摘要部分,如下所示:
myset = self.queryset
grosstotal = 0
for myline in myset:
if myline.jd_gross:
grosstotal += myline.jd_gross
ugrosstotal = intcomma(grosstotal)
self.band_summary.elements += [
SystemField(expression=ugrosstotal, top=1*cm, left=26.5*cm, width=1.9*cm, style={'alignment':TA_RIGHT}),
]
所以我的完整继承报告现在如下:
类 JobdetailsReport(DefaultReport): title = 'Job Details' page_size = Landscape(A4)
class band_detail(DetailBand):
height=0.7*cm
elements=[
ObjectValue(attribute_name='jd_job', left=0.1*cm),
ObjectValue(attribute_name='c_name', left=1.5*cm),
ObjectValue(attribute_name='clientname', left=5.8*cm),
ObjectValue(attribute_name='jd_return', left=10.1*cm),
ObjectValue(attribute_name='jd_delivery', left=12.6*cm),
ObjectValue(attribute_name='get_j_status1_display', left=15.1*cm),
ObjectValue(attribute_name='get_j_status2_display', left=17.6*cm),
ObjectValue(attribute_name='jd_prodref', left=20.1*cm),
ObjectValue(attribute_name='userformalname', left=23*cm),
ObjectValue(attribute_name='jd_gross', left=26.7*cm, width=1.7*cm, style={'alignment':TA_RIGHT}, get_value=lambda instance: intcomma(instance.jd_gross)),
]
borders = {'bottom': True}
class band_summary(ReportBand):
height = 1.7*cm
elements = [
Label(text='Records printed:', top=1*cm, left=0.5*cm),
ObjectValue(expression='count(jd_job)', top=1*cm, left=5.6*cm),
Label(text="Total Value:", top=1*cm, left=22*cm),
]
borders = {'top': True}
def __init__(self, *args, **kwargs):
super(JobdetailsReport, self).__init__(*args, **kwargs)
self.band_page_header.elements += [
Label(text="Job No.", top=0.8*cm, left=0.1*cm),
Label(text="Client", top=0.8*cm, left=1.5*cm),
Label(text="Delivery", top=0.8*cm, left=5.8*cm),
Label(text="Return", top=0.8*cm, left=10.1*cm),
Label(text="Delivery", top=0.8*cm, left=12.6*cm),
Label(text="Physical Status", top=0.8*cm, left=15.1*cm),
Label(text="Accts Status", top=0.8*cm, left=17.6*cm),
Label(text="Reference", top=0.8*cm, left=20.1*cm),
Label(text="Our Contact", top=0.8*cm, left=23*cm),
Label(text="Gross", top=0.8*cm, left=27*cm),
]
myset = self.queryset
grosstotal = 0
for myline in myset:
if myline.jd_gross:
grosstotal += myline.jd_gross
ugrosstotal = intcomma(grosstotal)
self.band_summary.elements += [
SystemField(expression=ugrosstotal, top=1*cm, left=26.5*cm, width=1.9*cm, style={'alignment':TA_RIGHT}),
]
希望对你有帮助!我只花了几个小时就让它工作了......