我应该用什么字段来输入密码?

时间:2017-06-25 20:08:42

标签: python django-models

我正在使用python版本3.5和django版本1.11。 我想知道我应该在pasword中使用哪个字段

models.py

from django.db import models
from django.db.models.signals import post_save
from django.contrib.auth.models import User


class Employee(models.Model):
    name = models.CharField(max_length=50,null=True)
    username = models.CharField(max_length=100,null=True)
    password = models.CharField(max_length=128)
    repeat_password = models.CharField(max_length=128)
    email = models.EmailField(max_length=70,null=True)
    phone_number = models.IntegerField(default=0)
    permanent_address = models.CharField(max_length=100,null=True)
    alternative_address = models.CharField(max_length=100,null=True)
    salary = models.IntegerField(default=0)
    join_date = models.DateField(null=True)
    paid_salary_date = models.DateField(null=True)
    designation = models.CharField(max_length=50,null=True)


    def __str__(self):
        return self.name

1 个答案:

答案 0 :(得分:2)

不要重新发明轮子,而是扩展Django User model,并将这些额外的字段添加到Employee类。您可以同样覆盖或定义新方法。

Extending the existing User model。事实上,文档中提供的示例是Employee类。

from django.contrib.auth.models import User

class Employee(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    department = models.CharField(max_length=100)