Hi all,
--------
There are simple model and tag:
--------
class Tag(models.Model):
name = models.CharField(max_length=50)
class Tour(models.Model):
name = models.CharField(max_length=50)
tags = models.ManyToManyField('Tag',
related_name='tours',)
--------
I want refactor data base to use django-tagging.
--------
class Tour(models.Model):
name = models.CharField(max_length=50)
tags = models.ManyToManyField('Tag',
related_name='tours',)
import tagging
tagging.register(Tour)
--------
First i do datamigration:
--------
./manage.py datamigration --freeze=tagging tour migrate_to_tagging
--------
Here i shold implement 'forward' and 'backward' methods.
How to do it? My wrong variant:
--------
class Migration(DataMigration):
def forwards(self, orm):
for tag in orm.Tag.objects.all():
for tour in tag.tours.all():
orm['tagging.Tag'].objects.add_tag(tour, tag.name)
def backwards(self, orm):
for tag in orm['tagging.Tag'].objects.all():
for tour in tag.tours.all():
tour.tags.add(tag.name)
--------
This is wrong:
--------
orm['tagging.Tag'].objects.add_tag(tour, tag.name)
AttributeError: 'Manager' object has no attribute 'add_tag'
--------
How to migrate data in right way
--
Regards, Andrey
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.