Hello,
I’m working on a project to replace a Drupal 6 application, and am trying to figure out how to use its MySQL ‘users’ table to create my Django user models. Both apps are housed on the same server so I have easy access to the db. The Drupal ‘users’ database is still actively used for a greater application from which my project is a subset, so I am not able to restructure it, and I’m hoping to avoid requiring separate accounts for my app since it is all part of the same ecosystem.
I’ve researched AbstractUser
and AbstractBaseUser
, but have not found a way to assign columns from an existing table to the username and password variables. All of the custom user model solutions seem to assume that the user database is starting fresh, and takes care of assigning, storing, and saving usernames and passwords behind the scenes.
I’m considering using a standard User model, checking unrecognized usernames and passwords against the Drupal User db, and creating a new Django user on the first login if it exists. Is this my best bet? It seems cumbersome but haven’t found a better solution.
What I’d like to do (or something of the sort):
class User(AbstractBaseUser):
uid = models.AutoField(primary_key=True)
username = models.CharField(unique=True, max_length=60)
password = models.CharField( max_length=32)
mail = models.CharField(max_length=64, blank=True, null=True)
USERNAME_FIELD = 'username'
class Meta:
managed = False
db_table = 'users'
Some other info:
I presume I’ll need to write a custom authentication backend to decode the hashed Drupal password as it is stored in the db, but I imagine this should be pretty easy once I have the model ironed out.
I’m pretty new to Django so forgive my ignorance. Thanks!