X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/133a8f939cdfa69dd6a7caeafed158aa38d20092..0ad5d07da08894c96caf49e05e9cf649e58d6554:/forum/migrations/0018_comments_to_node.py?ds=sidebyside diff --git a/forum/migrations/0018_comments_to_node.py b/forum/migrations/0018_comments_to_node.py index 1b10aee..808bb0e 100644 --- a/forum/migrations/0018_comments_to_node.py +++ b/forum/migrations/0018_comments_to_node.py @@ -12,6 +12,8 @@ class Migration(DataMigration): print "\nConverting %d comments:" % c_count progress = ProgressBar(c_count) + id_map = {} + for c in orm.Comment.objects.all(): node = orm.Node( node_type='comment', @@ -31,6 +33,8 @@ class Migration(DataMigration): ) node.save() + id_map[c.id] = node + revision = orm.NodeRevision( summary="Initial revsion", revision=1, @@ -59,6 +63,26 @@ class Migration(DataMigration): progress.update() print "\n...done\n" + + ctype = orm['contenttypes.ContentType'].objects.get(name="comment").id + ntype = orm['contenttypes.ContentType'].objects.get(name="node").id + + #Converting activity + activities = orm.Activity.objects.filter(content_type__id=ctype) + activity_count = activities.count() + print "Converting %d activity references:" % activity_count + progress = ProgressBar(activity_count) + + for a in activities: + node = id_map.get(a.object_id, None) + if node: + a.content_type_id = ntype + a.object_id = node.id + a.save() + + progress.update() + + print "\n...done\n" def backwards(self, orm):