# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-09-28 08:49
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.migrations.operations.special
from django.utils.text import slugify


def create_slugs(apps, schema_editor):
    """Create slugs for existing categories."""
    Category = apps.get_model("helpcenter", "Category")

    for category in Category.objects.all():
        slug = slugify(category.title)[:50]
        category.slug = slug
        category.save()


class Migration(migrations.Migration):

    dependencies = [
        ('helpcenter', '0008_article_draft'),
    ]

    operations = [
        migrations.AddField(
            model_name='category',
            name='slug',
            field=models.SlugField(null=True, verbose_name='Category URL Slug'),
        ),
        migrations.RunPython(
            code=create_slugs,
            reverse_code=migrations.RunPython.noop,
        ),
        migrations.AlterField(
            model_name='category',
            name='slug',
            field=models.SlugField(verbose_name='Category URL Slug'),
        ),
    ]
