La verdad es que me gustaría saber como puedo hacer una autentificación funcional para el este modelo que tengo que usa AbstracBaseUser
from __future__ import unicode_literals
from time import timezone
from django.db import models
from django.contrib.auth.models import AbstractBaseUser
from django.contrib.auth.models import BaseUserManager
from django.contrib.auth.models import PermissionsMixin
from django.core.mail import send_mail
from django.utils.translation import ugettext_lazy as _
from apps.people.models import People
class PersonalizadoBaseUserManager(BaseUserManager):
def _create_user(self, email, password, is_staff, is_superuser, **extra_fields):
if not email:
now = timezone.now()
raise ValueError('Debe tener un email')
email = self.normalize_email(email)
user = self.model(email=email,
is_staff=is_staff, is_active=True,
is_superuser=is_superuser, last_login=now,
date_joined=now, **extra_fields)
user.set_password(password)
user.save(using=self._db)
return user
def create_user(self, email, password=None, **extra_fields):
return self._create_user(email, password, False, False, **extra_fields)
def create_superuser(self, email, password, **extra_fields):
return self._create_user(email, password, True, True, **extra_fields)
class User(AbstractBaseUser,PermissionsMixin):
User = models.OneToOneField(People, blank=True, on_delete=models.CASCADE)
username = models.CharField(max_length=50, unique=True)
email = models.EmailField(blank=True, unique=True)
is_active = models.BooleanField(default=True)
is_staff = models.BooleanField(default=False)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['username', 'User']
objects = PersonalizadoBaseUserManager()
class Meta:
verbose_name = _('user')
verbose_name_plural = _('users')
def get_absolute_url(self):
return "/users/%$/" % urlquote(self.email)
La verdad necesito ayuda ya que las opciones que he usado no me han funcionado.