# Generated by Django 4.0.3 on 2022-04-20 20:40

import datetime
from django.db import migrations, models
from django.db.models import F
import django.db.models.deletion
import django.db.models.expressions
from django.utils.text import slugify


def forwards_func(apps, schema_editor):
    Tasks = apps.get_model("tasks", "Task")
    Tasks.objects.all().update(shortterm=slugify(F('name'))[1:26])
    Tasks.objects.all().update(slug=slugify(F('shortterm')))

    TaskLists = apps.get_model("tasks", "TaskList")
    TaskLists.objects.all().update(slug=slugify(F('shortterm')))


class Migration(migrations.Migration):

    dependencies = [
        ('tasks', '0001_initial'),
    ]

    operations = [
        migrations.AlterModelOptions(
            name='task',
            options={'ordering': ('task_list', django.db.models.expressions.OrderBy(django.db.models.expressions.F('due_date'), descending=True, nulls_first=True)), 'verbose_name': 'Aufgabe', 'verbose_name_plural': 'Aufgaben'},
        ),
        migrations.AddField(
            model_name='task',
            name='shortterm',
            field=models.CharField(blank=True, max_length=25, null=True),
        ),
        migrations.AddField(
            model_name='task',
            name='slug',
            field=models.SlugField(blank=True, max_length=25, null=True),
        ),
        migrations.AddField(
            model_name='tasklist',
            name='shortterm',
            field=models.CharField(blank=True, max_length=128, unique=True),
        ),
        migrations.AlterField(
            model_name='task',
            name='title',
            field=models.CharField(max_length=128, verbose_name='Titel'),
        ),
        migrations.AlterField(
            model_name='tasklist',
            name='name',
            field=models.CharField(max_length=128),
        ),
        migrations.CreateModel(
            name='Document',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('title', models.CharField(max_length=128, verbose_name='Titel')),
                ('shortterm', models.CharField(blank=True, max_length=20)),
                ('slug', models.SlugField(blank=True, max_length=20)),
                ('etherpad_key', models.CharField(blank=True, max_length=50)),
                ('date', models.DateField(default=datetime.date.today, verbose_name='Datum')),
                ('task', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='tasks.task')),
            ],
            options={
                'verbose_name': 'Dokument',
                'verbose_name_plural': 'Dokumente',
            },
        ),
        migrations.AddConstraint(
            model_name='document',
            constraint=models.UniqueConstraint(fields=('title', 'date', 'task'), name='unique_task_document'),
        ),
        migrations.RunPython(forwards_func),
        migrations.AlterField(
            model_name='task',
            name='shortterm',
            field=models.CharField(blank=True, max_length=25),
        ),
        migrations.AlterField(
            model_name='task',
            name='slug',
            field=models.SlugField(blank=True, max_length=25),
        ),
        migrations.AlterField(
            model_name='tasklist',
            name='slug',
            field=models.SlugField(blank=True, unique=True),
        ),
    ]
