30 lines
767 B
Python
30 lines
767 B
Python
from django.db import migrations, models
|
|
from django.utils.text import slugify
|
|
|
|
|
|
def slugify_name(apps, schema_editor):
|
|
Tool = apps.get_model('tasks', 'tool')
|
|
for tool in Tool.objects.all():
|
|
tool.slug = slugify(tool.name)
|
|
tool.save(update_fields=['slug'])
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
('tasks', '0001_initial'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.AddField(
|
|
model_name='tool',
|
|
name='slug',
|
|
field=models.SlugField(blank=True, null=True, unique=True),
|
|
),
|
|
migrations.RunPython(slugify_name),
|
|
migrations.AlterField(
|
|
model_name='tool',
|
|
name='slug',
|
|
field=models.SlugField(unique=True),
|
|
)
|
|
]
|