Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load Multiple Fixtures at Once

Is there anyway to load one fixture and have it load multiple fixtures?

I'd ideally like to type:

python manage.py loaddata all_fixtures 

And have that load all of the data instead of having to type everything. Is this possible?

like image 501
silent1mezzo Avatar asked Feb 08 '10 21:02

silent1mezzo


People also ask

How do I load all fixtures in Django?

By default, Django only loads fixtures into the default database. Use before_scenario to load the fixtures in all of the databases you have configured if your tests rely on the fixtures being loaded in all of them.

What are Django fixtures?

A fixture is a collection of data that Django knows how to import into a database. The most straightforward way of creating a fixture if you've already got some data is to use the manage.py dumpdata command.


2 Answers

I have multiple apps on the project directory and have each app with its 'fixtures' directory. So using some bash I can do:

python3 manage.py loaddata */fixtures/*.json

And that expands all of the json files inside of the fixtures directory on each app in my project. You can test it by simply doing:

ls */fixtures/*.json

like image 25
mimoralea Avatar answered Oct 11 '22 04:10

mimoralea


Using $ python manage.py loaddata myfixtures/*.json would work as Bash will substitute the wildcard to a list of matching filenames.

like image 115
speakman Avatar answered Oct 11 '22 05:10

speakman