My model:
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'])
Resources:
from import_export import resources
from models import TreeNode
class TreeNodeResource(resources.ModelResource):
class Meta:
model = TreeNode
View:
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
But this code exports only fields stored in database. How to add pay_progress
property value to the exported report?