Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple AUTH_USER_MODEL In django

In my Django project (which is a REST API) I'm having a problem that has probably been encountered before yet I can't find a good solution to it anywhere. In my project I have 2 different kinds of users, "Mobile app users" and "Business users". The mobile app users can go into our mobile app and see content around them based on geolocation. The business users can log on to a web admin portal and generate the content that the mobile app user sees. As a caveat there is also the possibility that a business user can also be an app user. I want to be able to allow a business user and an app user to have the same email while still having it be unique to their model.

Now Problem is how It is possible to create a two account(1st is mobile app & 2nd is business) with same Email ID..

like image 527
Anmol Monga Avatar asked Jan 25 '17 11:01

Anmol Monga


People also ask

Can I have two user models in Django?

No matter what strategy you pick, or what is your business model, always use one, and only one Django model to handle the authentication. You can still have multiple user types, but generally speaking it's a bad idea to store authentication information across multiple models/tables.

What is Auth_user_model in Django?

Django allows you to override the default user model by providing a value for the AUTH_USER_MODEL setting that references a custom model. Method 2 – AUTH_USER_MODEL : AUTH_USER_MODEL is the recommended approach when referring to a user model in a models.py file.

How do I create different roles in Django?

Groups: Way of Categorizing UsersDjango provides a basic view in the admin to create these groups and manage the permissions. The group denotes the “role” of the user in the system. As an “admin”, you may belong to a group called “admin”. As a “support staff”, you would belong to a group called “support”.

How many types of user in Django?

Initially, there are two types of users in a Django application: superuser accounts and regular users. Superusers have every attribute and privilege of regular accounts, but also have access to the Django admin panel, a powerful application that we'll explore in detail in a future article.


1 Answers

Possible solutions in general:

There is a few possible solutions to deal with different type of users. According to your situation you should. This article covers the subject in many ways: How to Implement Multiple User Types with Django

Approach discussed in the article summarized:

  1. Use always only one Django model to handle authentication, even if you have different type of users. As @Anton Perepelitcyn and @Anderw pointed out, we can still have multiple user models for other purposes using relations.
  2. According to your situation choose best solution for you:enter image description here
like image 137
Viljami Avatar answered Sep 20 '22 11:09

Viljami