Skip to content

Commit

Permalink
Merge pull request #4856 from rtfd/shorten-project-name
Browse files Browse the repository at this point in the history
Shorten project name to match slug length
  • Loading branch information
ericholscher authored Nov 2, 2018
2 parents ab78b3a + 6bfbce5 commit 235303d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ def forwards_func(apps, schema_editor):
project.slug = project.slug[:max_length]
project.save()

projects_invalid_name = (
Project
.objects
.annotate(name_length=Length('name'))
.filter(name_length__gt=max_length)
)
for project in projects_invalid_name:
project.name = project.name[:max_length]
project.save()


class Migration(migrations.Migration):

Expand All @@ -33,4 +43,9 @@ class Migration(migrations.Migration):
name='slug',
field=models.SlugField(max_length=63, unique=True, verbose_name='Slug'),
),
migrations.AlterField(
model_name='project',
name='name',
field=models.CharField(max_length=63, verbose_name='Name'),
),
]
2 changes: 1 addition & 1 deletion readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ class Project(models.Model):
# Generally from conf.py
users = models.ManyToManyField(User, verbose_name=_('User'),
related_name='projects')
name = models.CharField(_('Name'), max_length=255)
# A DNS label can contain up to 63 characters.
name = models.CharField(_('Name'), max_length=63)
slug = models.SlugField(_('Slug'), max_length=63, unique=True)
description = models.TextField(_('Description'), blank=True,
help_text=_('The reStructuredText '
Expand Down

0 comments on commit 235303d

Please sign in to comment.