2017-10-09 10 views
2

申し訳ありませんが、これは非常に基本的な質問ですが、is_activeのようなDjangoユーザーモデルのフィールド値がどこに保存されているのでしょうか?データベース内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) 

私は、データベースに表示されていないis_activeフィールド、アクセスすることができます。is_activeがデータベースに保存されていないPythonのクラスpropertyで、あなたのケースで

>>> from django.contrib.auth import get_user_model 
>>> u = get_user_model().objects.get(pk=45) 
>>> u.is_active 
False 

答えて

関連する問題