David542
David542

Reputation: 110163

Override django user with AUTH_USER_MODEL

I have override the default User model in my app with AUTH_USER_MODEL.

Here is the user model I want to use in my app, which is tied closely to a legacy database:

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

class User(AbstractUser):
    name = models.CharField(max_length=128, blank=True)
    email = models.EmailField(unique=True)
    password = models.CharField(max_length=128)
    is_active = models.BooleanField(default=True)
    is_admin = models.BooleanField(default=False)
    date_joined = models.DateTimeField(default=timezone.now)
    normalized_email = models.EmailField(unique=True)    

However, django complains that fields such as first_name, last_name, etc. are not provided. Is there a way to remove some of the existing fields in the User model? Or does specifying a custom user model only allow you to add additional fields on top of that? Is there a simple way to delete them, or do I basically have to add those fields (and ignore them) to our existing database in order to be able to use django with it?

Upvotes: 1

Views: 1255

Answers (1)

Alasdair
Alasdair

Reputation: 308839

AbstractUser is for when you want to add additional fields to Django's defaults. Use AbstractBaseUser if you don't want all those fields.

Upvotes: 3

Related Questions