0

I would like to extend and override the fields existing in the User model, which is found in "django.contrib.auth.models" (The model is already created). I first attempted to create a Foreign-Key and a One-to-One relationship between the User model, and a Client model (in which I added the extra fields), but I don't think it is good practice. How could I directly add and override fields within the User model and not have to create another class model to extend it.

from django.contrib.auth.models import User

class Clients(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
#client = models.OneToOneField(User, on_delete=models.CASCADE)
cell = models.PositiveIntegerField (blank=False)
address = models.CharField(default = "Sandton, JHB", blank = False, max_length=132)
0

1 Answer 1

1
from django.contrib.auth.models import AbstractUser

class CustomUser(AbstractUser):

    pass

Now in your settings.py file, add the following line

AUTH_USER_MODEL = "module.file.CustomUSer"
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.