Created
August 15, 2015 01:36
-
-
Save mlncn/68ca8b0dec7b3236ec13 to your computer and use it in GitHub Desktop.
Worst dedupe function ever, but example of manual migration runnnig a function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from __future__ import unicode_literals | |
from django.db import migrations | |
def dedupe_codes(apps, schema_editor): | |
codes = [] | |
count = 0 | |
measures = apps.get_model('measures', 'Measure') | |
for measure in measures.objects.all(): | |
if measure.code in codes: | |
count += 1 | |
measure.code = "deduped-{}-{}".format(count, measure.code) | |
measure.save() | |
codes.append(measure.code) | |
class Migration(migrations.Migration): | |
dependencies = [ | |
('measures', '0025_measure_aggregation'), | |
] | |
operations = [ | |
migrations.RunPython(dedupe_codes), | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment