我使用call_command来启动一个datadump,我想排除多个应用程序,所以如果我没有使用call_command,我会像django文档告诉我这样做:
from django.core.management import call_command
call_command("dumpdata", format="json", ?)
但是在call_command中,我不知道应该怎么称呼它:
call_command("dumpdata", format="json", exclude="app1")
call_command("dumpdata", format="json", exclude="app1 app2")
# CommandError: No installed app with label 'a'.
call_command("dumpdata", format="json", e="app1")
call_command("dumpdata", format="json", e="app1 app2")
# Does not fail but does not exclude anything either
call_command("dumpdata", format="json", e="app1", e="app2")
# SyntaxError: keyword argument repeated
什么不起作用:
private var storedUserState: UserState
var userState: UserState {
get {
return storedUserState
}
set {
print("Before: \(self.storedUserState)")
storedUserState = newValue
print("After: \(self.storedUserState)")
}
}
是否可以使用call_command从dumpdata中排除某些内容?
提前致谢。
答案 0 :(得分:0)
您应该使用列表来传递这样的参数:
call_command("dumpdata", format="json", e=["app1", "app2"])
错误没有安装带有标签'a'的应用程序,提示Django如何处理dumpdata命令(字符串“app1”被视为列表)。
答案 1 :(得分:0)
将此e用于此类排除
call_command('dumpdata','appname', '-etitanapp.databasebackup', format='json',indent=3,stdout=output)