有没有办法加载不驻留在 appname/fixtures 中的夹具?根据django 文档,灯具必须在 INSTALLED_APPS 目录中
问问题
377 次
2 回答
4
您可以使用以下设置定义其他位置来搜索固定装置FIXTURE_DIRS
:https ://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS
于 2012-01-18T02:47:05.190 回答
1
只需使用 call_command 以编程方式调用“loaddata”。你可以在setUp中做到这一点。
from django.test import TestCase
from django.core.management import call_command
class GlobalSetup(TestCase):
def setUp(self):
# Manually calling loaddata to import fixures
# that are not in INSTALLED_APPS
call_command('loaddata', 'cur_dir/fixtures_name', verbosity=0)
于 2012-01-18T02:29:28.670 回答