[Answered ]-Custom Django Authentication

2👍

I suggest the following options:

1.

I am assuming User model is the “real” user of your app. If this is true use the django’s default User model class. It will work out of the box.

For the Customer model, make it inherit from AbstractBaseUser, this will give you password functionality out of the box and you can add other fields as per your need.

Now you can create 2 different urls for login. 1 url for user which checks in the User model and the other for the customer model. This avoids any confusion for everyone.

If you prefer a single url, you have to mention the model class along with username and password to know in which table to verify them.

2.

Create two profile models: UserProfile and CustomerProfile

Each will have a one to one relationship with the django’s default User model.

Basically a User can have the profile of a “real” user or of a customer.

In this case when you are creating any User you have check if you want to attach a UserProfile or a CustomerProfile.

In this case it makes sense to just use a single login url. From the user’s login information you can first fetch the user from the User table and then check if it is a customer or not by running a query in the CustomerProfile table.

0👍

I recommend you to use the django.contrib.auth.user class for your classical authentication. You can either inherit from that class or add a OneToOne relation to your own model as follows

from django.contrib.auth.models import User

class YourUser(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)

For the rest of your question you should add some more details and even some pieces of your code.

Leave a comment