I'd like to call the equivalent of manage.py loaddata
from a Django view. I'd like to be able to specify where to load the data from and which application to load it into.
Any ideas?
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.
Ans: To load data into Django you have to use the command line Django-admin.py loaddata. The command line will searches the data and loads the contents of the named fixtures into the database.
To fix this, first close the terminal window and relaunch it with administrator privileges. Once you launch the elevated terminal window change directory to where you wish to start your Django project. The command should work.
Each django-admin.py
(manage.py
) command, as seen in the documentation, you can call from your code with:
from django.core.management import call_command call_command('loaddata', 'myapp')
Where first param is the command name, all other position params are the same as command line position params and all keyword params are options.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With