2
对不起,如果这是一个非常基本的问题,但我想知道Django用户模型字段值如is_active
的保存位置,因为我没有在数据库中看到它们。Django用户模型字段在哪里保存?
我使用的是自定义的用户模型,但他们仍必须保存的地方... :)
models.py
class MyUserManager(BaseUserManager):
def create_user(self, username, email, password=None):
"""
Creates and saves a User with the given email and password.
"""
if not email:
raise ValueError('Users must have an email address')
user = self.model(
email=self.normalize_email(email),
)
self.username = username
user.set_password(password)
user.save(using=self._db)
return user
...
class MyUser(AbstractBaseUser):
email = models.EmailField(
verbose_name='email address',
max_length=255,
unique=True,
)
is_active = False
objects = MyUserManager()
USERNAME_FIELD = 'email'
...
表在数据库:
Schema | Name | Type | Owner
--------+------------------------+-------+------------
public | auth_group | table | xxx
public | auth_group_permissions | table | xxx
public | auth_permission | table | xxx
public | django_admin_log | table | xxx
public | django_content_type | table | xxx
public | django_migrations | table | xxx
public | django_session | table | xxx
public | drillapp_myuser | table | xxx
public | drillapp_question | table | xxx
public | drillapp_story | table | xxx
(10 rows)
这是用户表的外观。否is_active
列。
drill=# select * from drillapp_myuser;
id | password | last_login | email
----+---------------------------------------+------------+----------------------
45 | pbkdf2_sha256$36000$GNzjZ...edPewC28= | | [email protected]
(1 row)
在shell我可以访问is_active
场,我不会在数据库中看到:
>>> from django.contrib.auth import get_user_model
>>> u = get_user_model().objects.get(pk=45)
>>> u.is_active
False