Corrections to Blog.entry_tags to use taggit APIs. Tweaks to penfield migration 0005...
[philo.git] / philo / contrib / penfield / migrations / 0005_to_taggit.py
index 00fa9ac..52090c6 100644 (file)
@@ -3,6 +3,7 @@ import datetime
 from south.db import db
 from south.v2 import DataMigration
 from django.db import models
+from philo.migrations import person_model, frozen_person
 
 class Migration(DataMigration):
 
@@ -38,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()
 
@@ -94,19 +97,7 @@ class Migration(DataMigration):
                        'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
                        'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
                },
-               'oberlin.person': {
-                       'Meta': {'object_name': 'Person'},
-                       'bio': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
-                       'degree_type': ('django.db.models.fields.CharField', [], {'max_length': '3', 'blank': 'True'}),
-                       'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
-                       'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
-                       'graduation_year': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
-                       'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-                       'name': ('django.db.models.fields.CharField', [], {'max_length': '70', 'blank': 'True'}),
-                       'phone': ('django.contrib.localflavor.us.models.PhoneNumberField', [], {'max_length': '20', 'blank': 'True'}),
-                       't_number_hash': ('django.db.models.fields.CharField', [], {'max_length': '60', 'blank': 'True'}),
-                       'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True', 'null': 'True', 'blank': 'True'})
-               },
+               person_model: frozen_person,
                'penfield.blog': {
                        'Meta': {'object_name': 'Blog'},
                        'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
@@ -115,7 +106,7 @@ class Migration(DataMigration):
                },
                'penfield.blogentry': {
                        'Meta': {'ordering': "['-date']", 'object_name': 'BlogEntry'},
-                       'author': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'blogentries'", 'to': "orm['oberlin.Person']"}),
+                       'author': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'blogentries'", 'to': "orm['%s']" % person_model}),
                        'blog': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'entries'", 'null': 'True', 'to': "orm['penfield.Blog']"}),
                        'content': ('django.db.models.fields.TextField', [], {}),
                        'date': ('django.db.models.fields.DateTimeField', [], {'default': 'None'}),
@@ -153,7 +144,7 @@ class Migration(DataMigration):
                },
                'penfield.newsletterarticle': {
                        'Meta': {'ordering': "['-date']", 'unique_together': "(('newsletter', 'slug'),)", 'object_name': 'NewsletterArticle'},
-                       'authors': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'newsletterarticles'", 'symmetrical': 'False', 'to': "orm['oberlin.Person']"}),
+                       'authors': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'newsletterarticles'", 'symmetrical': 'False', 'to': "orm['%s']" % person_model}),
                        'date': ('django.db.models.fields.DateTimeField', [], {'default': 'None'}),
                        'full_text': ('philo.models.fields.TemplateField', [], {'db_index': 'True'}),
                        'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
@@ -253,4 +244,5 @@ class Migration(DataMigration):
                }
        }
 
-       complete_apps = ['penfield']
+       complete_apps = ['penfield', 'taggit']
+       symmetrical = True