我如何在南方使用django-allauth?

时间:2013-08-15 08:42:12

标签: python django django-south django-allauth

我正在尝试使用South进行数据迁移。我想将存储在django-allauth的SocialAccount模型中的信息迁移到我自己的UserProfile模型中。但是,我在将django-allauth导入数据迁移文件时遇到问题。这是我到目前为止所做的:

class Migration(DataMigration):

    def forwards(self, orm):
        "Write your forwards methods here."
        # Note: Don't use "from appname.models import ModelName". 
        # Use orm.ModelName to refer to models in this application,
        # and orm['appname.ModelName'] for models in other applications.
        for user in orm['auth.User'].objects.all():
            import allauth.socialaccount.models
            print dir(user)
            prof = orm.UserProfile(user=user)
            prof.name = "%s %s" % (user.first_name, user.last_name)
            prof.is_ghost = False
            prof.has_facebook = True if len(user.socialaccount_set.all()) > 0 else False

            prof.save()

运行时,我得到:

AttributeError: 'User' object has no attribute 'socialaccount_set'

我检查了user的命名空间,似乎socialaccount_set不存在。但是,当我在shell中测试它时它就存在了,我一直在我的应用程序中使用它。有什么想法吗?

0 个答案:

没有答案