Skip to content

Instantly share code, notes, and snippets.

@sanjaykrishnan
Created December 20, 2018 04:58
Show Gist options
  • Save sanjaykrishnan/bdef5ab19428cfcf647c62d10b5832dc to your computer and use it in GitHub Desktop.
Save sanjaykrishnan/bdef5ab19428cfcf647c62d10b5832dc to your computer and use it in GitHub Desktop.
Management Command
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