Autocreate superuser with each schema django

喜夏-厌秋 提交于 2019-12-12 02:09:59

问题


I'm working on a multi tenant app using django-tenant-schema(and postgresql). Now as soon as the new schema is getting created, I'm using the call_command to create a superuser. I also thought of the option of using signal post_migrate.

My doubt is how can I auto create a superuser without typing the password in shell. The use case is as soon as the user registers for his/her schema, a superuser is generated and the user logs in with the superuser username and password and can change the password thereafter.

I'm using the following to call the createsuperuser command:

call_command('createsuperuser', schema_name=self.schema_name, username='admin', email='admin@admin.com')

One way to solve the issue is to change Django's createsuperuser.py file and provide a password over there automatically, buts thats not an acceptable route, ie cahnging the source code for some use case. Could I please request for some better methods


回答1:


you can "prepare" password for new superuser and pass md5 value to bash:

a=# select md5('some password'||'test');;
               md5
----------------------------------
 d5b3eb515b64edf295b2ee9062946d24
(1 row)

a=# create user test superuser password 'md5d5b3eb515b64edf295b2ee9062946d24';
CREATE ROLE

so you can use d5b3eb515b64edf295b2ee9062946d24 in bash, saving password somewhere else?..



来源:https://stackoverflow.com/questions/38019532/autocreate-superuser-with-each-schema-django

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