def copy_bookmarks_from_user_to_prolfies()

in pulseapi/profiles/migrations/0005_copy_user_bookmarks.py [0:0]


def copy_bookmarks_from_user_to_prolfies(apps, schema_editor):
    EmailUser = apps.get_model('users', 'EmailUser')
    ProfileUserBookmarks = apps.get_model('profiles', 'UserBookmarks')
    UserProfile = apps.get_model('profiles', 'UserProfile')

    current_bookmarks = apps.get_model('users', 'UserBookmarks').objects.all()
    for bookmark in current_bookmarks:
        user = EmailUser.objects.get(id=bookmark.user.id)
        profile = UserProfile.objects.get(user=user)

        (nbm, created) = ProfileUserBookmarks.objects.get_or_create(
            user=user,
            profile=profile,
            entry=bookmark.entry,
            timestamp=bookmark.timestamp
        )

        if created is True:
            msg = "created a parallel bookmark between user:{u} and entry:{e}"
            msg = msg.format(u=user.id, e=bookmark.entry.id)
            print(msg)