我想用我的数据生成器函数遍历几个模型。目前我的页面没有加载,只是说无法访问此网站。谁知道我做错了什么?
# Reset database
models = ['ReservedItem', 'Ticket', 'Event', 'Organizer', 'User']
for _model_name in models:
**_model_name.objects.all().delete()
print("Deleted ", model_name)
答案 0 :(得分:1)
不需要您尝试执行的字符串映射,假设您的模型全部导入到您正在执行此操作的文件中:
models = [ReservedItem, Ticket, Event, Organizer, User]
for m in models:
m.objects.all().delete()
print("Deleted {}".format(m._meta.label))