Changeset View
Changeset View
Standalone View
Standalone View
films/migrations/0057_enforce_collection_slug.py
- This file was added.
| # Generated by Django 3.0.9 on 2020-12-07 10:44 | |||||
| from django.db import migrations, models | |||||
| from django.db.models.query_utils import Q | |||||
| import common.upload_paths | |||||
| def fill_collection_slugs(apps, schema_editor): | |||||
| Collection = apps.get_model('films', 'Collection') | |||||
| for collection in Collection.objects.filter( | |||||
| Q(slug__isnull=True) | Q(slug='') | |||||
| ): | |||||
| collection.slug = common.upload_paths.shortuid() | |||||
| collection.save(update_fields=['slug']) | |||||
| class Migration(migrations.Migration): | |||||
| dependencies = [ | |||||
| ('films', '0056_allow_blank_summary'), | |||||
| ] | |||||
| operations = [ | |||||
| migrations.RunPython(fill_collection_slugs, reverse_code=migrations.RunPython.noop), | |||||
| migrations.AlterField( | |||||
| model_name='collection', | |||||
| name='slug', | |||||
| field=models.SlugField(default=common.upload_paths.shortuid), | |||||
| ), | |||||
| ] | |||||