# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-09-29 22:47
from __future__ import unicode_literals

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


def create_article_slugs(apps, schema_editor):
    """Create slugs for existing articles."""
    Article = apps.get_model("helpcenter", "Article")

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


class Migration(migrations.Migration):

    dependencies = [
        ('helpcenter', '0009_category_slug_squashed_0011_auto_20160928_0840'),
    ]

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