Skip to content

Instantly share code, notes, and snippets.

@hnykda
Last active July 6, 2018 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hnykda/79db90398af36408eb520c12758e1e20 to your computer and use it in GitHub Desktop.
Save hnykda/79db90398af36408eb520c12758e1e20 to your computer and use it in GitHub Desktop.
def migrate_data(apps, schema_editor):
Tracker = apps.get_model('campaign', 'Tracker')
Syncer = apps.get_model('campaign', 'Syncer')
Key = apps.get_model('attribute', 'Key')
for k in Key.objects.all():
c = k.parent_campaign
if c.campaign_type == 'Panel':
new_camp = Syncer.objects.get(cid=c.cid)
else:
new_camp = Tracker.objects.get(cid=c.cid)
logger.debug('processing key %s for %s -> %s', k, c, new_camp)
k.parent_campaign_new = new_camp # Key.parent_campaign_new is GenericForeignKey
k.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment