Django中的默认权限/组数据 [英] Default permission/group data in Django
问题描述
每次在测试期间(或在克隆或部署时)擦除Django应用程序的数据库时,都必须进入/admin并设置权限和组.我将把用它们填充数据库的代码放在哪里,又将是什么样?
Every time I wipe the database of my Django app during testing (or when cloning or deployin), I have to go into /admin and set up permissions and groups. Where would I put the code that would populate the DB with them and what would it look like?
推荐答案
为此,您可以使用固定装置.
For this you can use fixtures.
例如:
python manage.py dumpdata auth > fixtures/auth.json
这会将包auth的所有模型(用户,组关系)存储到auth.json中 部署后,您可以使用以下命令进行加载:
This will store all models of package 'auth' (Users, Groups Relations) into auth.json After Deployment you can use the following command to load:
python manage.py loaddata auth fixtures/auth.json
这将恢复您先前的身份验证"状态.
This will restore your prev state of 'auth'.
也许最好切换到 South ,这是Django非常著名的一部分,可以迁移数据库而不是迁移数据库重新创建它们.
Maybe it's good for you to switch to South, a very famous part of Django to migrate databases instead of recreating them.
这篇关于Django中的默认权限/组数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!