Imports and Exports django model to excel and csv
python >= 3
Django 1.11.5, >= 2.11
pip install model-import-export
Creating resources
In your example_app/resources.py
from model_import_export.resources import ModelResource, ForeignKeyResource, ManyToManyResource
from dashboard.models import *
class UserResource(ModelResource):
class Meta:
model = User
fields = '__all__'
Exporting model
from .resources import UserResource
queryset = User.objects.all()
resource = UserResource(queryset)
resource.to_excel('users.xlsx')
Importing model
resource = UserResource()
resource.from_excel('users.xlsx')