简体   繁体   中英

How to implement different users in django rest framework?

I am building an app using django rest framework and react. I have installed rest auth, all auth for user authentication. When i create a super user from console using manage.py createsuperuser or manually add from django admin panel then i can login from route 'rest-auth/login' & get a generated token. But now i want add a different user called Doctor who can access limited features.I want to register the doctor user from django admin. But here i want to register the doctor by only email address & password not user name & password. So the question is how to make a custom user called doctor in django rest framework. Last thing, i have no user model in models.py cause django rest auth handling all staff about user.Important thing is i want to differ all users by email & user name. If i get the user by username & password then i will assume it as a hospital owner & if i can login using email & password then it will be a doctor.

First, create your custom user model, it has been always recommended to go with your custom user model.

If you are in the beginning of your project it will be easy to do it, if not follow this

Considering your roles, check this it may be helpful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM