Reputation: 1871
Trying to use django-registration module with custom user model that extends AbstractBaseUser
.
This is a form, I use for the registration:
from django.contrib.auth import get_user_model
from registration.forms import RegistrationForm
class UserCreateForm(RegistrationForm):
class Meta:
fields = ("username", "email", "password1", "password2")
model = get_user_model()
This is the view:
class Register(RegistrationView):
form_class = forms.UserCreateForm
This is my registration url:
url(r'^accounts/register/$', views.Register.as_view(), name='registration_register'),
Edit:
Django does not send confirmation email, and browser throws an error
'User' object has no attribute 'email_user'
Edit:
I understand I have to implement email_user method in my custom user model. How can I do this?
Upvotes: 0
Views: 2428
Reputation: 1872
Here is an example of the email_user
from the Django AbstractUser class.
from django.contrib.auth.models import AbstractBaseUser
from django.core.mail import send_mail
class CustomUser(AbstractBaseUser):
...
def email_user(self, subject, message, from_email=None, **kwargs):
"""Send an email to this user."""
send_mail(subject, message, from_email, [self.email], **kwargs)
Upvotes: 0
Reputation: 1871
I just needed to add email_user method to my custom user model
def email_user(self, *args, **kwargs):
send_mail(
'{}'.format(args[0]),
'{}'.format(args[1]),
'{}'.format(args[2]),
[self.email],
fail_silently=False,
)
Upvotes: 3