changed all_names to alternate_names, added counter to monitor progress
Be sure your mysql server is set to utf8: http://stackoverflow.com/questions/3513773/change-mysql-default-characte r-set-to-utf8-in-my-cnf 2nd answerpull/1/head
parent
63c6b35a30
commit
e4259bf468
|
@ -12,7 +12,7 @@ class Migration(SchemaMigration):
|
|||
db.create_table('core_publishername', (
|
||||
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
|
||||
('name', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
|
||||
('publisher', self.gf('django.db.models.fields.related.ForeignKey')(related_name='all_names', null=True, to=orm['core.Publisher'])),
|
||||
('publisher', self.gf('django.db.models.fields.related.ForeignKey')(related_name='alternate_names', null=True, to=orm['core.Publisher'])),
|
||||
))
|
||||
db.send_create_signal('core', ['PublisherName'])
|
||||
|
||||
|
@ -220,7 +220,7 @@ class Migration(SchemaMigration):
|
|||
'Meta': {'object_name': 'PublisherName'},
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
|
||||
'publisher': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'all_names'", 'null': 'True', 'to': "orm['core.Publisher']"})
|
||||
'publisher': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'alternate_names'", 'null': 'True', 'to': "orm['core.Publisher']"})
|
||||
},
|
||||
'core.rightsholder': {
|
||||
'Meta': {'object_name': 'RightsHolder'},
|
||||
|
|
|
@ -7,6 +7,8 @@ from django.db import models
|
|||
class Migration(DataMigration):
|
||||
|
||||
def forwards(self, orm):
|
||||
n=0
|
||||
m=0
|
||||
for edition in orm.Edition.objects.all():
|
||||
if edition.publisher and edition.publisher != '':
|
||||
try:
|
||||
|
@ -16,12 +18,24 @@ class Migration(DataMigration):
|
|||
pub_name.save()
|
||||
edition.publisher_name = pub_name
|
||||
edition.save()
|
||||
n += 1
|
||||
if n==10000:
|
||||
m += 1
|
||||
n=0
|
||||
print str(m*10000)+" "
|
||||
|
||||
def backwards(self, orm):
|
||||
n=0
|
||||
m=0
|
||||
for edition in orm.Edition.objects.all():
|
||||
if edition.publisher_name:
|
||||
edition.publisher = edition.publisher_name.name
|
||||
edition.save()
|
||||
n += 1
|
||||
if n==10000:
|
||||
m += 1
|
||||
n=0
|
||||
print str(m*10000)+" "
|
||||
|
||||
models = {
|
||||
'auth.group': {
|
||||
|
@ -183,7 +197,7 @@ class Migration(DataMigration):
|
|||
'Meta': {'object_name': 'PublisherName'},
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
|
||||
'publisher': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'all_names'", 'null': 'True', 'to': "orm['core.Publisher']"})
|
||||
'publisher': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'alternate_names'", 'null': 'True', 'to': "orm['core.Publisher']"})
|
||||
},
|
||||
'core.rightsholder': {
|
||||
'Meta': {'object_name': 'RightsHolder'},
|
||||
|
|
|
@ -178,7 +178,7 @@ class Migration(SchemaMigration):
|
|||
'Meta': {'object_name': 'PublisherName'},
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
|
||||
'publisher': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'all_names'", 'null': 'True', 'to': "orm['core.Publisher']"})
|
||||
'publisher': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'alternate_names'", 'null': 'True', 'to': "orm['core.Publisher']"})
|
||||
},
|
||||
'core.rightsholder': {
|
||||
'Meta': {'object_name': 'RightsHolder'},
|
||||
|
|
|
@ -986,8 +986,7 @@ class Publisher(models.Model):
|
|||
class PublisherName(models.Model):
|
||||
name = models.CharField(max_length=255, blank=False)
|
||||
|
||||
# all_names was a bad choice. should be "alternate_names"
|
||||
publisher = models.ForeignKey('Publisher', related_name='all_names', null=True)
|
||||
publisher = models.ForeignKey('Publisher', related_name='alternate_names', null=True)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.name
|
||||
|
|
Loading…
Reference in New Issue