2

I am making a website through Django and I want to create a similar model for the Users model (default user model came with Django) I have tried everything I have found from google django docs and I couldn't.

Can anyone help? Or help me to make a login system for my normal model

For an instance,
I have created a normal model called accounts and there is a field in it called loggedin. Whenever I try to login system set it to True means logged in. And if i logged out by the logout button i set it to false now lets take in consideration if i have closed the web browser Immediately i want to set it to False Any help?

1 Answer 1

3

There are two common ways to deal with is extending django's AbstractUser:

from django.db import models
from django.contrib.auth.models import AbstractUser

class User(AbstractUser):
    # Some other fields to go along with the default fields
    info = models.TextField(max_length=500, blank=True)
    phone_number = models.CharField(max_length=30, blank=True)
    birth_date = models.DateField(null=True, blank=True)

After this, just change the default user model on your settings.py adding AUTH_USER_MODEL = my_app.models.user

Sign up to request clarification or add additional context in comments.

2 Comments

I can now use all the methods like authenticate()¿
Yes. You see, you are just extending django's default user. Your user model will have all fields and all methods from de parent user, plus the new ones you add.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.