简体   繁体   中英

Extending the AbstractUser Model in Django

What are the attributes that are defined in the Django AbstractUser model?

I have extended the model:

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

class User(AbstractUser):
    pass

Do I have to create my own fields for username, first name, last name, etc? Or are they already defined?

Here you can find these fields are already defined. https://github.com/django/django/blob/master/django/contrib/auth/models.py#L288

However if you want user class without these fields look for AbstractBaseUser class https://github.com/django/django/blob/master/django/contrib/auth/base_user.py#L47

Yes those fields (username, email, first_name, last_name, is_staff, is_active, date_joined) are already defined for the AbstractUser. You can view the fields in the django admin. Check the source code here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM