Skip to content

Pass QerySet Manually and save result file #1419

Closed Answered by matthewhegarty
Javokhir-1999 asked this question in Q&A
Discussion options

You must be logged in to vote

Is it possible to do this using django-import-export?. (manually without web interface)

Yes. it is possible. Take a look at the documentation to get started. you need to define a Resource object, then you call export() to get a tablib Dataset. You can then export this dataset to Excel.

I suggest posting further questions to StackOverflow

For example:

class BookResource(resources.ModelResource):

    class Meta:
        model = Book
        fields = ('id', 'author__name')


resource = BookResource()
dataset = resource.export()

with open('/tmp/output.xlsx', 'wb') as f:
    f.write(dataset.export('xlsx'))

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Javokhir-1999
Comment options

Answer selected by Javokhir-1999
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants