From d4dc37e4305f53b0df0c070b52a2ac0d607c02ed Mon Sep 17 00:00:00 2001 From: Nick Sergeant Date: Wed, 15 Jun 2011 22:53:05 -0400 Subject: [PATCH] Working on tag import --- migrate.py | 8 +- snipts/admin.py | 1 - .../0007_auto__del_field_snipt_old_tags.py | 96 +++++++++++++++++++ snipts/models.py | 1 - 4 files changed, 99 insertions(+), 7 deletions(-) create mode 100644 snipts/migrations/0007_auto__del_field_snipt_old_tags.py diff --git a/migrate.py b/migrate.py index 4830406..b5c47a3 100644 --- a/migrate.py +++ b/migrate.py @@ -6,6 +6,7 @@ from django.contrib.auth.models import User from snipts.models import Comment, Snipt from taggit.models import Tag, TaggedItem +from taggit.utils import parse_tags conn = MySQLdb.connect(host='localhost', user='root', passwd='root', db='sniptold') cursor = conn.cursor() @@ -98,11 +99,8 @@ def snipts(): public=public, created=created, ) - - tags = tags.split(',') - for t in tags: - snipt.tags.add(t.strip()) - + for t in parse_tags(tags): + snipt.tags.add(t) snipt.save() print 'Done with snipts' diff --git a/snipts/admin.py b/snipts/admin.py index 91e9546..0e9811e 100644 --- a/snipts/admin.py +++ b/snipts/admin.py @@ -9,7 +9,6 @@ class CommentInline(admin.TabularInline): allow_add = False class SniptAdmin(admin.ModelAdmin): - readonly_fields = ('user',) list_display = ('title', 'slug', 'user', 'lexer', 'public', 'created', 'modified',) search_fields = ('title', 'user__username', 'tags', 'lexer', 'id',) ordering = ('created',) diff --git a/snipts/migrations/0007_auto__del_field_snipt_old_tags.py b/snipts/migrations/0007_auto__del_field_snipt_old_tags.py new file mode 100644 index 0000000..ebda599 --- /dev/null +++ b/snipts/migrations/0007_auto__del_field_snipt_old_tags.py @@ -0,0 +1,96 @@ +# encoding: utf-8 +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + +class Migration(SchemaMigration): + + def forwards(self, orm): + + # Deleting field 'Snipt.old_tags' + db.delete_column('snipts_snipt', 'old_tags') + + + def backwards(self, orm): + + # Adding field 'Snipt.old_tags' + db.add_column('snipts_snipt', 'old_tags', self.gf('django.db.models.fields.CharField')(default='', max_length=255), keep_default=False) + + + models = { + 'auth.group': { + 'Meta': {'object_name': 'Group'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), + 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) + }, + 'auth.permission': { + 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, + 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + 'auth.user': { + 'Meta': {'object_name': 'User'}, + 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), + 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), + 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) + }, + 'contenttypes.contenttype': { + 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, + 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) + }, + 'snipts.comment': { + 'Meta': {'object_name': 'Comment'}, + 'comment': ('django.db.models.fields.TextField', [], {}), + 'created': ('django.db.models.fields.DateTimeField', [], {}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'snipt': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['snipts.Snipt']"}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}) + }, + 'snipts.snipt': { + 'Meta': {'object_name': 'Snipt'}, + 'code': ('django.db.models.fields.TextField', [], {}), + 'created': ('django.db.models.fields.DateTimeField', [], {}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'key': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'lexer': ('django.db.models.fields.CharField', [], {'max_length': '50'}), + 'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'public': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50', 'db_index': 'True'}), + 'stylized': ('django.db.models.fields.TextField', [], {}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}) + }, + 'taggit.tag': { + 'Meta': {'object_name': 'Tag'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '100', 'db_index': 'True'}) + }, + 'taggit.taggeditem': { + 'Meta': {'object_name': 'TaggedItem'}, + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'taggit_taggeditem_tagged_items'", 'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'object_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True'}), + 'tag': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'taggit_taggeditem_items'", 'to': "orm['taggit.Tag']"}) + } + } + + complete_apps = ['snipts'] diff --git a/snipts/models.py b/snipts/models.py index d0e4148..0e197b3 100644 --- a/snipts/models.py +++ b/snipts/models.py @@ -11,7 +11,6 @@ class Snipt(models.Model): title = models.CharField(max_length=255) slug = models.SlugField() tags = TaggableManager() - old_tags = models.CharField(max_length=255) lexer = models.CharField(max_length=50) code = models.TextField()