Created
October 6, 2011 17:29
-
-
Save ojii/1268033 to your computer and use it in GitHub Desktop.
This file contains 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 multiprocessing import Process | |
from django.core import serializers | |
from django.core.management import call_command | |
from StringIO import StringIO | |
def dump_database(): | |
sio = StringIO() | |
call_command('dumpdata', stdout=sio, natural=True) | |
return sio.getvalue() | |
def call_command_with_db(dbdump, *args, **kwargs): | |
objects = serializers.deserialize('json', dbdump) | |
for obj in objects: | |
obj.save() | |
return call_command(*args, **kwargs) | |
def do_something(): | |
dbdump = dump_database() | |
process = Process(target=call_command_with_db, args=(dbdump, 'runserver',)) | |
process.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment