Skip to content

Commit

Permalink
wip management command for data migration
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentporte committed Sep 10, 2024
1 parent aae5479 commit d2ce576
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

from lacommunaute.documentation.models import Category
from lacommunaute.forum.models import Forum


def create_categories_from_cat_forums():
transpositions = []
for category_forum in Forum.objects.filter(type=1, level=0):
category = Category.objects.create(
name=category_forum.name,
short_description=category_forum.short_description,
description=category_forum.description,
image=category_forum.image,
)
transpositions.append((category_forum, category))
return transpositions


def link_forums_to_categories(transpositions):
for category_forum, category in transpositions:
for forum in category_forum.get_descendants():
forum.category = category
forum.parent = None
forum.save()


def add_redirections(transpositions):
for category_forum, category in transpositions:
Redirection.objects.create(old_path=category_forum.get_absolute_url(), new_path=category.get_absolute_url())


def delete_cat_forums(transpositions):
Forum.objects.filter(id__in=[forum.id for forum, _ in transpositions]).delete()

0 comments on commit d2ce576

Please sign in to comment.