I noticed if I comment out the line password = ReadOnlyPasswordHashField() in admin.py that I no longer run into this issue when saving, but then the field becomes editable and shows the hash.
from django.db import models
from django.contrib.auth.models import (
BaseUserManager, AbstractBaseUser, PermissionsMixin)
class UPDUserManager(BaseUserManager):
def create_user(self, email, first_name, last_name, password=None):
"""Create and save a user with the given email, first name,
last name and password.
"""
if not email:
raise ValueError("Users must have an email address.")
if not first_name:
raise ValueError("Users must have a first name.")
if not last_name:
raise ValueError("Users must have a last name.")
user = self.model(email=UPDUserManager.normalize_email(email),
first_name=first_name,
last_name=last_name,)
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self, email, first_name, last_name, password):
"""Create and save a superuser with the given email, first name,
last name and password.
"""
user = self.create_user(email, first_name=first_name,
last_name=last_name, password=password)
user.is_staff = True
user.is_superuser = True
user.save(using=self._db)
return user
class UPDUser(AbstractBaseUser, PermissionsMixin):
"""Inherit from both the AbstractBaseUser and PermissionsMixin."""
email = models.EmailField(verbose_name='email address', max_length=255,
unique=True, db_index=True)
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
is_active = models.BooleanField(default=True)
is_staff = models.BooleanField(default=False)
objects = UPDUserManager()
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['first_name', 'last_name']
def get_full_name(self):
"""Return the first_name and last_name."""
return "%s %s" % (self.first_name, self.last_name)
def get_short_name(self):
"""Return the first_name."""
return self.first_name
def __unicode__(self):
"""Return the user's email address."""
return self.email
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8ca0a1e2-ff36-4b30-98ad-985a8dfb9050%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment