Created
December 20, 2018 04:58
-
-
Save sanjaykrishnan/bdef5ab19428cfcf647c62d10b5832dc to your computer and use it in GitHub Desktop.
Management Command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.management import BaseCommand | |
from apps.accounts.admin import UserResource | |
from django.contrib.auth import get_user_model | |
import time | |
class Command(BaseCommand): | |
# Show this when the user types help | |
help = "Export all User data" | |
# A command must define handle() | |
def handle(self, *args, **options): | |
start_time = time.clock() | |
model = get_user_model() | |
user_resource = UserResource() | |
queryset = model.objects.all().order_by('id') | |
dataset = user_resource.export(queryset) | |
with open('user_data.xls', 'wb') as f: | |
f.write(dataset.xls) | |
print(time.clock() - start_time) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment