Here's the two ways i found to dump data from Django application.
- using
django-dbbackupmodule - using django
dumpdata.
As the django-dbbackup documentation states, we need to install the module django-dbbackup (django-dbbackup==3.3.0 latest at the time).
Then we need to add these to the settings.py:
DBBACKUP_STORAGE = "django.core.files.storage.FileSystemStorage"
DBBACKUP_STORAGE_OPTIONS = {"location": "/var/log/greedybear/"}and this to INSTALLED_APPS:
INSTALLED_APPS = {
...
# db backups
"dbbackup",Then from django call
from django.core import management
def backup_db():
management.call_command("dbbackup")According to this stackoverflow and this article we can run:
dumpdata > db.jsonto dump the data to json. Now we need to run it from code.
import os
from cStringIO import StringIO
from django.core import management
def create_fixture(app_name, filename):
buf = StringIO()
management.call_command('dumpdata', app_name, stdout=buf)
buf.seek(0)
with open(filename, 'w', 'utf-8') as f:
f.write(buf.read())Hope it Helped, if you found another way or if not working comment below.