Skip to content

Commit

Permalink
Merge pull request #1396 from Amsterdam-Music-Lab/fix-er/double-exper…
Browse files Browse the repository at this point in the history
…iment-slug-migration

catch for duplictate slugs already in databae
  • Loading branch information
Evert-R authored Nov 22, 2024
2 parents e5e7a77 + 5a2b714 commit 49831c4
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ class Migration(migrations.Migration):
def forwards_func(apps, schema_editor):
Experiment = apps.get_model('experiment', 'Experiment')
for experiment in Experiment.objects.all():
experiment.slug_temp = experiment.slug
if Experiment.objects.filter(slug=experiment.slug).count() > 1:
experiment.slug_temp = f"{experiment.slug}-{experiment.id}"
else:
experiment.slug_temp = experiment.slug
experiment.save()

def reverse_func(apps, schema_editor):
Expand Down

0 comments on commit 49831c4

Please sign in to comment.