Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

filter on django-import-export

I want to create csv file form my model send a dictionary of Queries ( filter exclude ) to django-import-export and return data from my model.

using flowing code i have all of model fields but i need to filter them with a query.

from import_export import resources
from finance.models import Price

class ExportData(resources.ModelResource):

    class Meta:
        model = Price
like image 944
rezakamalifard Avatar asked Jul 22 '13 14:07

rezakamalifard


1 Answers

Pass queryset to export method:

queryset = Price.objects.exclude(...)
data = ExportData().export(queryset)
data.csv
like image 152
bmihelac Avatar answered Oct 02 '22 08:10

bmihelac