from django.db import migrations, models
from django.utils.text import slugify
from django.utils.translation import gettext_lazy as _


def populate_tag_slugs(apps, schema_editor):
    Tag = apps.get_model('links', 'Tag')
    for tag in Tag.objects.all():
        tag.slug = slugify(tag.name)
        tag.save()


class Migration(migrations.Migration):

    dependencies = [
        ('links', '0032_remove_post_type'),
    ]

    operations = [
        migrations.AddField(
            model_name='tag',
            name='slug',
            field=models.SlugField(max_length=100, null=True, unique=True, verbose_name=_('Slug')),
        ),
        migrations.AddField(
            model_name='tag',
            name='description',
            field=models.TextField(blank=True, verbose_name=_('Description')),
        ),
        migrations.RunPython(populate_tag_slugs, reverse_code=migrations.RunPython.noop),
        migrations.AlterField(
            model_name='tag',
            name='slug',
            field=models.SlugField(max_length=100, unique=True, verbose_name=_('Slug')),
        ),
    ]
