[Django]-Django JSON fixture generation

2👍

Django’s admin site is great for quickly entering dummy data or initial data. You can then dump that to a json file (or whatever format).

http://docs.djangoproject.com/en/dev/ref/django-admin/#dumpdata-appname-appname-appname-model

django-admin.py dumpdata | pbcopy will dump all the data in json format to your clipboard.

Be careful with dumping contenttypes and auth tables as that may cause problems when loading the fixture back in to a database.

1👍

Check out django-dilla. It generates random data for your models, even images. Useful for testing without the tedium of manually entering data into admin.

👤Lyle

0👍

Simple data dump of all data in project to a Json fixture

python manage.py dumpdata --format=json myapp > /path/to/myapp/fixtures/initial_data.json

Then in tests.py add this to include fixtures:

class ViewTests(TestCase):

    # load fixtures
    fixtures = ['data2.json']

        def setUp(self):
        # continue remainder of test code

Leave a comment