Skip to content

Commit d71bb7f

Browse files
committed
Add migration
1 parent 5177ad6 commit d71bb7f

File tree

2 files changed

+36
-55
lines changed

2 files changed

+36
-55
lines changed

readthedocs/projects/migrations/0024_auto_20171229_1546.py

-55
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11.16 on 2018-11-01 20:55
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
from django.db.models.functions import Length
7+
8+
9+
def forwards_func(apps, schema_editor):
10+
max_length = 63
11+
Project = apps.get_model('projects', 'Project')
12+
projects_invalid_slug = (
13+
Project
14+
.objects
15+
.annotate(slug_length=Length('slug'))
16+
.filter(slug_length__gt=max_length)
17+
)
18+
for project in projects_invalid_slug:
19+
project.slug = project.slug[:max_length]
20+
project.save()
21+
22+
23+
class Migration(migrations.Migration):
24+
25+
dependencies = [
26+
('projects', '0029_add_additional_languages'),
27+
]
28+
29+
operations = [
30+
migrations.RunPython(forwards_func),
31+
migrations.AlterField(
32+
model_name='project',
33+
name='slug',
34+
field=models.SlugField(max_length=63, unique=True, verbose_name='Slug'),
35+
),
36+
]

0 commit comments

Comments
 (0)