I'm trying to include custom fields for the Django allauth SignUp form without much success. I've created the following forms and models:
models.py
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class UserProfile(models.Model):
user = models.OneToOneField(User, related_name='profile', unique=True)
# The additional attributes we wish to include.
website = models.URLField(blank=True)
picture = models.ImageField(upload_to='profile_images', blank=True)
def __unicode__(self):
return self.user.username
forms.py
from django.contrib.auth import get_user_model
from django import forms
from .models import UserProfile
class SignupForm(forms.ModelForm):
class Meta:
model = get_user_model()
fields = ('username', 'password', 'email', 'website', 'picture')
def save(self, user):
profile.save()
user.save()
settings.py
AUTH_USER_MODEL = 'user_app.UserProfile'
ACCOUNT_SIGNUP_FORM_CLASS = 'user_app.forms.SignupForm'
I've receiving the following error: AttributeError: type object 'UserProfile' has no attribute 'REQUIRED_FIELDS'
In order to override templates for django-allauth, you need to create accounts/ directory in your templates folder and add html pages with the names of the pages you want to change.
You need to define a tuple called REQUIRED_FIELDS
in your model:
class UserProfile(models.Model):
REQUIRED_FIELDS = ('user',)
user = models.OneToOneField(User, related_name='profile', unique=True)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With