Default permission/group data in Django

假如想象 提交于 2019-12-24 02:55:10

问题


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?


回答1:


For this you can use fixtures.

For example:

python manage.py dumpdata auth > fixtures/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'.

Maybe it's good for you to switch to South, a very famous part of Django to migrate databases instead of recreating them.




回答2:


You can provide fixtures with the initial required data and it will be automatically inserted when you syncdb. See docs



来源:https://stackoverflow.com/questions/22457733/default-permission-group-data-in-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!