X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/f5ef756179b62eb9a87983936c2576586632d8d7..37f95f6fd3e1da107a0eaf28c516e71206100bf4:/philo/contrib/penfield/migrations/0005_to_taggit.py diff --git a/philo/contrib/penfield/migrations/0005_to_taggit.py b/philo/contrib/penfield/migrations/0005_to_taggit.py index d6e41b4..52090c6 100644 --- a/philo/contrib/penfield/migrations/0005_to_taggit.py +++ b/philo/contrib/penfield/migrations/0005_to_taggit.py @@ -39,21 +39,23 @@ class Migration(DataMigration): def backwards(self, orm): "Write your backwards methods here." - import pdb - pdb.set_trace() BlogEntry = orm['penfield.BlogEntry'] NewsletterArticle = orm['penfield.NewsletterArticle'] Tag = orm['philo.Tag'] TaggitTag = orm['taggit.Tag'] TaggedItem = orm['taggit.TaggedItem'] + ContentType = orm['contenttypes.contenttype'] + + entry_ct = ContentType.objects.get(app_label="penfield", model="blogentry") + article_ct = ContentType.objects.get(app_label="penfield", model="newsletterarticle") for entry in BlogEntry.objects.all(): - tag_slugs = list(TaggitTag.objects.filter(taggit_taggeditem_items__content_object=entry).values_list('slug', flat=True)).distinct() + tag_slugs = list(TaggitTag.objects.filter(taggit_taggeditem_items__content_type=entry_ct, taggit_taggeditem_items__object_id=entry.pk).values_list('slug', flat=True).distinct()) entry.tags = Tag.objects.filter(slug__in=tag_slugs) entry.save() for article in NewsletterArticle.objects.all(): - tag_slugs = list(TaggitTag.objects.filter(taggit_taggeditem_items__content_object=article).values_list('slug', flat=True)).distinct() + tag_slugs = list(TaggitTag.objects.filter(taggit_taggeditem_items__content_type=article_ct, taggit_taggeditem_items__object_id=article.pk).values_list('slug', flat=True).distinct()) article.tags = Tag.objects.filter(slug__in=tag_slugs) article.save() @@ -242,4 +244,5 @@ class Migration(DataMigration): } } - complete_apps = ['penfield'] + complete_apps = ['penfield', 'taggit'] + symmetrical = True