将django-social-auth与自定义用户模型相关联:UserSocialAuth.user必须是“登录”实例

时间:2013-12-29 23:52:21

标签: python django facebook django-socialauth

我需要帮助才能将django-social-auth与我的自定义用户模型连接起来:

SOCIAL_AUTH_USER_MODEL = 'login.Login'

因此,新用户将在我的登录应用程序中创建。这是我得到的错误:

Django Version: 1.5.5
Exception Type: ValueError
Exception Value: Cannot assign "<django.utils.functional.SimpleLazyObject object at 0x10be47090>": 
"UserSocialAuth.user" must be a "Login" instance.

以下是我的settings.py的样子:

INSTALLED_APPS = (
    ...
    'social_auth',
)

AUTHENTICATION_BACKENDS = (
    'social_auth.backends.facebook.FacebookBackend',
    'django.contrib.auth.backends.ModelBackend',
)

SOCIAL_AUTH_ENABLED_BACKENDS = ('facebook',)
SOCIAL_AUTH_DEFAULT_USERNAME = 'new_social_auth_user'

FACEBOOK_APP_ID = 'xxx'
FACEBOOK_API_SECRET = 'xxx'

SOCIAL_AUTH_BACKEND_ERROR_URL = '/login/'
LOGIN_REDIRECT_URL = '/'
LOGIN_ERROR_URL = '/login/'
LOGIN_URL = '/complete/facebook'

SOCIAL_AUTH_USER_MODEL = 'login.Login'

这是登录的模型:

from django.db import models

class Login(models.Model):
    username = models.CharField(max_length=30)
    password = models.CharField(max_length=200)
    email = models.EmailField(blank=True, null=True)
    creation_date = models.DateTimeField(auto_now_add=True)
    is_active = models.BooleanField(default=True)

    def __unicode__(self):
        return u'%s %s %s' % (self.username, self.email, self.creation_date)

    class Meta(object):
        verbose_name_plural = "Login"

我错过了什么?谢谢你的帮助!

0 个答案:

没有答案