自定义用户模型django-allauth的AssertionError

时间:2013-09-17 16:23:03

标签: python django django-allauth

我是django的新手,最近我决定整合django allauth使用登录(facebook和google +),我使用自定义模型(django 1.5),以及一对一userprofile模型,我的自定义模型类长相

class MyUser(AbstractBaseUser):   
   email = models.EmailField(
      verbose_name='email address',
      max_length=255,
      unique=True,
      db_index=True,
   )
   username = models.CharField(max_length=35,  blank=False)
   is_active = models.BooleanField (default=False)
   is_admin = models.BooleanField (default=False)

  objects = MyUserManager()

  USERNAME_FIELD = 'email'
  REQUIRED_FIELDS = ['username']

和我的用户个人资料:

class UserProfile(models.Model):
   phone = models.FloatField(blank=True, null=True)
   is_visible = models.BooleanField (default=True)
   user = models.OneToOneField(MyUser, primary_key=True)

这里是django allauth local_settings文件:

ACCOUNT_AUTHENTICATION_METHOD = "email"
ACCOUNT_SIGNUP_FORM_CLASS = 'bloodi.accounts.forms.RegistrationForm'
ACCOUNT_LOGOUT_ON_GET = True
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_UNIQUE_EMAIL = True

通过这种配置,我遇到了django allauth的两个问题:
   *)它不允许重复的用户名    *)注册过程中的应用程序崩溃(似乎用户帐户必须处于活动状态才能继续登录)

AssertionError 
Exception Location: \allauth\account\utils.py in perform_login, line 110
...
assert user.is_active

1 个答案:

答案 0 :(得分:1)

Django不允许重复的用户名,请参阅:

https://docs.djangoproject.com/en/dev/topics/auth/customizing/#django.contrib.auth.models.CustomUser.USERNAME_FIELD

至于断言错误,请使用:

is_active = models.BooleanField(default=True)