Skip to content

Instantly share code, notes, and snippets.

@trepca
Created October 23, 2010 19:57
Show Gist options
  • Save trepca/642623 to your computer and use it in GitHub Desktop.
Save trepca/642623 to your computer and use it in GitHub Desktop.
class Migration(DataMigration):
def forwards(self, orm):
for todo in orm.Todo.objects.all():
if todo.all_day or todo.location:
obj = orm.Event()
obj.all_day = todo.all_day
obj.location = todo.location
obj.end_date = todo.due_date
else:
obj = orm.Task()
obj.due_date = todo.due_date
obj.title = todo.title
obj.start_date = todo.start_date
obj.due_date = todo.due_date
obj.date_created = todo.date_created
obj.owner = todo.owner
obj.save()
if todo.body:
note = orm.Note(body=todo.body)
note.save()
obj.notes.add(note)
def backwards(self, orm):
"all data is only copied anyway, so no backward code needed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment