1
votes

I've created a custom user model (AbstractBaseUser) so that user could login into my website.

The problem is that I want to keep using Django's default user and authentication system for the admin so that staff could easily log in and manage stuff.

I saw a lot of tutorials but all of the instruct to change the setting AUTH_USER_MODEL, but if I change that I won't be able to keep using Django's default user.

Is there any solution for this?

Thanks in advance.

1

1 Answers

0
votes

I have never implemented this myself, but to point you in the right direction, it may be worth having a read through this:

https://docs.djangoproject.com/en/1.10/topics/auth/customizing/#authentication-backends

By the sounds of things you may be able to write an authentication backend for your front end user model, that you can run in tandem with Django's authentication system.

If you could get this to work, I would imagine that you would then have to make sure that the front end user model, once authenticated, can not access the admin part of the site.

For me the million dollar question here is, why do you want to keep the front end and backend users on separate models? They both have the same job, to authenticate the user?

I've created several projects in the past where there are front end users and admin users. Out of the box, without any modification you set the user attribute is_staff=False for front end users and is_staff=True for the admin users; that determines whether or not a user can access the admin part of the site, and I've never had any issues with this approach.

If the front end user (or backend user) desires additional functionality, the simplest solution would be to extend the user model:

https://docs.djangoproject.com/en/1.10/topics/auth/customizing/#extending-the-existing-user-model

Alternatively you could user your could create a custom user model and use this for both.

If you're willing to provide more details, perhaps I could help further, but unless there's a strong reason for having separate user models, I'd just stick with the one and configure and extend as you need.

I hope this helps.