# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import migrations class Migration(migrations.Migration): def rebuild_refmap(apps, schema_editor): Post = apps.get_model('boards', 'Post') for post in Post.objects.all(): refposts = list() for refpost in post.referenced_posts.all(): result = '>>{}'.format(refpost.get_absolute_url(), self.id) if refpost.is_opening(): result = '{}'.format(result) refposts += result post.refmap = ', '.join(refposts) post.save(update_fields=['refmap']) dependencies = [ ('boards', '0024_post_tripcode'), ] operations = [ migrations.RunPython(rebuild_refmap), ]