2017-09-06 11 views
0

私はdjangoが作成したpostgresqlデータベーステーブルについて混乱しています。 psqlコマンドから私のユーザテーブルに関する情報を得ました。最初のcolmunは、last_loginフィールドです。しかしlast_loginフィールドはどこにも設定しません。Djangoデータベースモデル

テーブル定義は次のとおりです。

remoshin_devdb=# \d remosys_remoshin_user_tbl; 
    Table "public.remosys_remoshin_user_tbl" 
    Column  |   Type   | Modifiers 
-----------------+--------------------------+----------- 
last_login  | timestamp with time zone | 
userid   | character varying(64) | not null 
username  | character varying(128) | not null 
email   | character varying(254) | not null 
password  | character varying(128) | not null 
usertype  | character varying(1)  | not null 
is_active  | character varying(1)  | not null 
is_admin  | character varying(1)  | not null 
u_kana_name  | character varying(128) | 
u_date_of_birth | date      | 
u_gender  | character varying(1)  | not null 
u_postno  | character varying(7)  | 
u_address1  | character varying(128) | 
u_address2  | character varying(128) | 
u_telno   | character varying(16) | 
u_photo   | character varying(100) | 
d_photo   | character varying(100) | 
create_date  | timestamp with time zone | not null 
modify_date  | timestamp with time zone | not null 
d_clinic_id_id | character varying(8)  | 
Indexes: 
    "remosys_remoshin_user_tbl_pkey" PRIMARY KEY, btree (userid) 
    "remosys_remoshin_user_tbl_email_key" UNIQUE CONSTRAINT, btree (email) 
    "remosys_remoshin_user_tbl_d_clinic_id_id_65dbde14" btree (d_clinic_id_id) 
    "remosys_remoshin_user_tbl_d_clinic_id_id_65dbde14_like" btree (d_clinic_id_id varchar_pattern_ops) 
    "remosys_remoshin_user_tbl_email_4dc9031b_like" btree (email varchar_pattern_ops) 
    "remosys_remoshin_user_tbl_userid_e92979ce_like" btree (userid varchar_pattern_ops) 
Foreign-key constraints: 
    "remosys_remoshin_use_d_clinic_id_id_65dbde14_fk_remosys_c" FOREIGN KEY (d_clinic_id_id) REFERENCES remosys_clinic_tbl(clinic_id) DEFERRABLE 
INITIALLY DEFERRED 
Referenced by: 
    TABLE "authtoken_token" CONSTRAINT "authtoken_token_user_id_35299eff_fk_remosys_r" FOREIGN KEY (user_id) REFERENCES remosys_remoshin_user_tbl(userid) DEFERRABLE INITIALLY DEFERRED 
    TABLE "django_admin_log" CONSTRAINT "django_admin_log_user_id_c564eba6_fk_remosys_r" FOREIGN KEY (user_id) REFERENCES remosys_remoshin_user_tbl(userid) DEFERRABLE INITIALLY DEFERRED 
    TABLE "remosys_consultation_menu_tbl" CONSTRAINT "remosys_consultation_user_email_id_4e50d1dc_fk_remosys_r" FOREIGN KEY (user_email_id) REFERENCES remosys_remoshin_user_tbl(userid) DEFERRABLE 
    INITIALLY DEFERRED 
    TABLE "remosys_consultation_tbl" CONSTRAINT "remosys_consultation_user_id_5541f93d_fk_remosys_r" FOREIGN KEY (user_id) REFERENCES remosys_remoshin_user_tbl(userid) DEFERRABLE INITIALLY DEFERRED 
TABLE "remosys_refund_request_tbl" CONSTRAINT "remosys_refund_reque_user_email_id_f46e5866_fk_remosys_r" FOREIGN KEY (user_email_id) REFERENCES remosys_remoshin_user_tbl(userid) DEFERRABLE 
INITIALLY DEFERRED 

私のユーザーモデルは以下のとおりです。 last_loginフィールドは使用しません。私は何が起こっているのか理解していません。助けてください。あなたがlast_loginフィールドを持つAbstractBaseUserを継承しているので、

class RemoshinUserManager(BaseUserManager): 

    def create_user(self, userid, username, email, password): 
     """ Creates and saves User with the given email and password. """ 
     # now = timezone.now() 
     if not email: 
      raise ValueError('Users must have an email address.') 
     email = self.normalize_email(email), 
     user = self.model(
      userid=userid, 
      username=username, 
      email=email, 
      is_active='A', 
      # last_login=now, 
      # date_joined=now, 
      # **extra_fields 
     ) 

     user.set_password(password) 
     user.save(using=self._db) 
     return user 

    def create_superuser(self, userid, username, email, password): 
     """ Creates and saves a superuser with the given email and password. """ 
     user = self.create_user(userid, username, email, password) 
     user.is_active = 'A' 
     # user.is_staff = True 
     user.is_admin = 'A' 
     # user.is_superuser = True 
     user.save(using=self._db) 
     return user 


class RemoshinUser(AbstractBaseUser): 
    userid = models.CharField('userID', max_length=64, primary_key=True) 
    username = models.CharField('user name', max_length=128) 
    email = models.EmailField('email address', unique=True) 
    password = models.CharField('password', max_length=128) 

    USERTYPE_CHOICE = (
     ('U', 'end user'), 
     ('C', 'doctor'), 
     ('A', 'administrator'), 
    ) 
    usertype = models.CharField('user type', max_length=1, choices=USERTYPE_CHOICE, default='U') 

    # is_authenticated = models.BooleanField('authentication flag', default=True) 

    ACTIVETYPE_CHOICE = { 
     ('A', 'active'), 
     ('I', 'inactive'), 
    } 
    is_active = models.CharField('active flag', max_length=1, choices=ACTIVETYPE_CHOICE, default='A') 

    ADMINTYPE_CHOICE = { 
     ('A', 'administrator'), 
     ('N', 'normal user'), 
    } 
    is_admin = models.CharField('administrator flag', max_length=1, choices=ADMINTYPE_CHOICE, default='N') 

    # For Enduser 
    u_kana_name = models.CharField('user kana name', max_length=128, blank=True, null=True) 
    u_date_of_birth = models.DateField('date of birth', blank=True, null=True) 
    # u_gender = models.SmallIntegerField('gender', blank=True, null=True) 

    GENDER_CHOICES = (
     ('M', 'male'), 
     ('F', 'female'), 
    ) 
    u_gender = models.CharField('gender', max_length=1, choices=GENDER_CHOICES, default='M') 

    u_postno = models.CharField('post no', max_length=7, blank=True, null=True) 
    u_address1 = models.CharField('address 1', max_length=128, blank=True, null=True) 
    u_address2 = models.CharField('address 2', max_length=128, blank=True, null=True) 
    u_telno = models.CharField('tel no', max_length=16, blank=True, null=True) 
    u_photo = models.ImageField('user photo', upload_to='users/%Y/%m/%d', blank=True, null=True) 

    # For Doctor 
    d_clinic_id = models.ForeignKey(Clinic, blank=True, null=True) 
    d_photo = models.ImageField('doctor photo', blank=True, null=True) 

    # For administrator 
    # No column is defined. 

    create_date = models.DateTimeField('create date', default=timezone.now) 
    modify_date = models.DateTimeField('modify date', default=timezone.now) 

    objects = RemoshinUserManager() 

    USERNAME_FIELD = 'userid' 
    REQUIRED_FIELDS = ['username', 'email'] 

    class Meta: 
     db_table = 'remosys_remoshin_user_tbl' 

答えて

3

class AbstractBaseUser(models.Model): 
    password = models.CharField(_('password'), max_length=128) 
    last_login = models.DateTimeField(_('last login'), blank=True, null=True) 
    # . 
    # . 
    # . 

REF:github source

+0

ありがとうございます。それは私にとって大きな助けになります。 –

1

私はそれについて心配しないでしょう。 Djangoはあなたの将来の利便性のために多くのことを含んでおり、そのようなフィールドはその一つです。

私が便利に来ていることを想像できる場所がたくさんあります -

など、管理ページから顧客サービス、フィードに新しいストーリーを表示することを確認をすることは、使用する任意の圧力を感じてはいけないが、それはどこにでもあるが、ただそれを残すだけで傷つくことはない。

関連する問題