Skip to content

Commit

Permalink
catch for duplictate slugs already in databae
Browse files Browse the repository at this point in the history
  • Loading branch information
Evert-R committed Nov 22, 2024
1 parent 488f818 commit 5a2b714
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 5a2b714

Please sign in to comment.