I have three Django projects: Project A, Project B, and Project C. Project A serves as the authentication project, Project B is responsible for managing user-related functionalities, and Project C handles restaurant-related operations.
In Project A, I have created a custom user model to suit my authentication requirements. Now, I want to utilize this custom user model to access the APIs of both Project B and Project C.
How can I achieve this integration between the projects? Specifically, I would like to accomplish the following:
Enable user authentication: I want to use the custom user model defined in Project A to authenticate users when they access the APIs of Project B and Project C.
Share user information: I need to access user information from Project B and Project C using the custom user model defined in Project A. This includes retrieving user details, updating user profiles, and performing user-related operations.
Maintain consistency: It is essential to ensure that any changes made to the custom user model in Project A are reflected across all projects, including Project B and Project C.
Here is my Custom user Model from Project A.
import uuid
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin
from django.db import models
from django.utils import timezone
class UserManager(BaseUserManager):
def _create_user(self, email, password, is_staff, is_superuser, **extra_fields):
if not email:
raise ValueError('Users must have an email address')
now = timezone.now()
email = self.normalize_email(email)
user = self.model(
email=email,
is_staff=is_staff,
is_active=True,
is_superuser=is_superuser,
last_login=now,
date_joined=now,
**extra_fields
)
user.set_password(password)
user.save(using=self._db)
return user
def create_user(self, email, password, **extra_fields):
return self._create_user(email, password, False, False, **extra_fields)
def create_superuser(self, email, password, **extra_fields):
user = self._create_user(email, password, True, True, **extra_fields)
return user
class User(AbstractBaseUser, PermissionsMixin):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
# username = models.CharField(max_length=255, null=True, blank=True, unique=True)
email = models.EmailField(max_length=254)
name = models.CharField(max_length=254, null=True, blank=True)
is_staff = models.BooleanField(default=False)
is_superuser = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
last_login = models.DateTimeField(null=True, blank=True)
date_joined = models.DateTimeField(auto_now_add=True)
organization_id = models.UUIDField(null=True, blank=True)
USERNAME_FIELD = 'email'
EMAIL_FIELD = 'email'
REQUIRED_FIELDS = []
objects = UserManager()
def get_absolute_url(self):
return "/users/%i/" % (self.pk)
I have already tried this solution ( Using same database table with two different projects Django ). But it is not working. Or somehow I am not implemented it correctly. If this is the solution please give a full example of it.your text