I have a django project in which I have 3 types of users (Student, Store, College) each connected to a seperate model class by One-to-one relation (not add user groups or anything) . Now I want to check if a user of a given extended model class(Student user) is authenticated or not. The aim is to redirect the (Student)user from login page directly to homepage if he is already logged in.
I tried to implement this by using:
def entry(request): if request.user.is_authenticated: print("Already logged in") return redirect('home') else: return render (request, 'tray/entry.html')
but then it’ll redirect from login to homepage even if any user from another user type(such as user of Store or College model) is authenticated, thus causing error of missing session data for rendering the student home page on this faulty redirect skipping login.
I would be very grateful if someone could suggest a way to solve this with minimum changes and also what the best practice method would be for multiple users onetoone extended models. Thanks in advance.