# Generated by Django 5.2.9 on 2025-12-11 13:13 from django.db import migrations from django.utils.text import slugify def gen_slugs(apps, schema_editor): MyModel = apps.get_model('hadis', 'HadisCategory') # Replace with your app/model name for row in MyModel.objects.all(): # 1. Basic slugify base_slug = slugify(row.title) # Assuming you slugify the 'name' field slug = base_slug n = 1 # 2. Ensure uniqueness (if two rows have the same name) while MyModel.objects.filter(slug=slug).exists(): slug = f"{base_slug}-{n}" n += 1 row.slug = slug row.save() class Migration(migrations.Migration): dependencies = [ ("hadis", "0005_auto_20251209_1620"), ] operations = [ migrations.RunPython(gen_slugs, reverse_code=migrations.RunPython.noop), ]