我的模型:
class TreeNode(MPTTModel):
...
@property
def pay_progress(self):
return "{}/{}".format(self.annuities.exclude(fact_date=None).aggregate(Sum('total'))['total__sum'] or 0,
self.annuities.aggregate(Sum('total'))['total__sum'])
资源:
from import_export import resources
from models import TreeNode
class TreeNodeResource(resources.ModelResource):
class Meta:
model = TreeNode
看法:
def export_treenode_csv(request):
treenode_resource = TreeNodeResource()
dataset = treenode_resource.export()
response = HttpResponse(dataset.xls, content_type='application/vnd.ms-excel')
response['Content-Disposition'] = 'attachment; filename="TreeNode.xls"'
return response
但是此代码仅导出存储在数据库中的字段。如何为pay_progress
导出的报告添加属性值?