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