我正在尝试扩展Django-allauth中的基本用户配置文件。注册表单正确加载,但在提交表单后,“列用户名不是唯一错误”。
项目文件如下:
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='userprofile')
# The additional attributes we wish to include.
website = models.URLField(blank=True)
picture = models.ImageField(upload_to='profile_images', blank=True)
has_accepted_tos = models.BooleanField(default=False,
verbose_name='I accept site rules')
#REQUIRED_FIELDS = ['has_accepted_tos']
def __unicode__(self):
return self.user.username
User.profile = property(lambda u:UserProfile.objects.get_or_create(user=u)[0])
forms.py
from django.contrib.auth import get_user_model
from .models import UserProfile
from django.forms import CharField, BooleanField, ModelForm
from django.utils.translation import ugettext as _
from allauth.account.adapter import get_adapter
# forms.py
class SignupForm(ModelForm):
has_accepted_tos = BooleanField(error_messages={'required': _('You must accept the terms and conditions')},
label=_('I accept site terms and conditions'),
required=True)
class Meta:
#model = get_user_model
model = UserProfile
fields = ('website', 'picture', 'has_accepted_tos')
def signup(self, request, user):
adapter = get_adapter()
user = adapter.new_user(request)
adapter.save_user(request, user, self)
我怀疑注册方法没有正确实现。有人可以建议吗?