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
です。ただし、シェルでテストすると存在し、アプリケーション全体で使用しています。何かご意見は?