mirror of
https://github.com/boostorg/website-v2.git
synced 2026-01-19 04:42:17 +00:00
Add migration to repopulate slug field based on library key
This commit is contained in:
21
libraries/migrations/0020_repopulate_slug_20240325_1616.py
Normal file
21
libraries/migrations/0020_repopulate_slug_20240325_1616.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from django.db import migrations
|
||||
from django.utils.text import slugify
|
||||
|
||||
from libraries.models import Library
|
||||
|
||||
|
||||
def migrate_to_key_slug(apps, schema_editor):
|
||||
"""Migrate the key to the slug field."""
|
||||
|
||||
for library in Library.objects.all():
|
||||
library.slug = slugify(library.key)
|
||||
library.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("libraries", "0019_merge_20240218_0058"),
|
||||
]
|
||||
|
||||
operations = [migrations.RunPython(migrate_to_key_slug)]
|
||||
@@ -139,7 +139,8 @@ class Library(models.Model):
|
||||
"""
|
||||
# Generate slug based on name
|
||||
if not self.slug:
|
||||
slug = slugify(self.name)
|
||||
# Base the slug name off of the key from the gitmodules file.
|
||||
slug = slugify(self.key)
|
||||
|
||||
# If there is a library with that slug, try a slug based on the key from the
|
||||
# gitmodules file
|
||||
|
||||
Reference in New Issue
Block a user