Reputation: 173
Im learning about django, and i need create a customized user, called Person. I use inherit from contrib.auth.models User, but in my django administrator the form for add a new Teacher dont show the field confirm password and the password is not encrypted in the table user
from django.db import models
from django.contrib.auth.models import User, UserManager
# Create your models here.
class Person (User):
date_of_birth = models.DateField(blank=False, null=False)
class Meta:
abstract = True
class ClassRoom (models.Model):
classroom = models.CharField(max_length=3, blank=False, null=False)
def __unicode__(self):
return self.classroom
class Teacher(Person):
phone = models.PositiveIntegerField(max_length=15, blank=False, null=False)
classroom = models.ManyToManyField(ClassRoom)
You can see in this photo as the first and second users is saved encripting the password(this users was added as normal user in the django administrator), but the last(creadted as Teacher in the django administrator) dont encrypt the pass.
¿Someone can help me? database photo user table
Upvotes: 1
Views: 1204
Reputation: 2575
In order to encrypt a password, you need to set it through User's set_password
method. for example,
user = User(
email=email, is_staff=False, is_active=True,
is_superuser=False,
last_login=now, date_joined=now, **extra_fields)
user.set_password(password)
user.save(using=self._db)
Upvotes: 4