From 4930178675ea38cc8072c4d1cfdd6288d9573466 Mon Sep 17 00:00:00 2001 From: vincent porte Date: Tue, 24 Sep 2024 10:33:47 +0200 Subject: [PATCH] update taggeditems of Forum migrated into Document --- .../management/commands/migrate_documentation.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lacommunaute/documentation/management/commands/migrate_documentation.py b/lacommunaute/documentation/management/commands/migrate_documentation.py index 5bb2a5a95..05b5a8a2b 100644 --- a/lacommunaute/documentation/management/commands/migrate_documentation.py +++ b/lacommunaute/documentation/management/commands/migrate_documentation.py @@ -1,6 +1,8 @@ import sys +from django.contrib.contenttypes.models import ContentType from django.core.management.base import BaseCommand +from taggit.models import TaggedItem from lacommunaute.documentation.models import Category, Document from lacommunaute.forum.models import Forum @@ -26,8 +28,10 @@ def create_categories_from_catforums(): def create_document_from_forums(category_transpo_dict): # TODO next : # add redirections when get_absolute_url is setup - # migrate UpVotes and TaggedItems + # migrate UpVotes + forum_content_type = ContentType.objects.get_for_model(Forum) + document_content_type = ContentType.objects.get_for_model(Document) transpo_dict = {} for forum in Forum.objects.filter(parent__type=1): @@ -40,6 +44,9 @@ def create_document_from_forums(category_transpo_dict): partner=forum.partner, certified=forum.certified, ) + TaggedItem.objects.filter(content_type=forum_content_type, object_id=forum.id).update( + content_type=document_content_type, object_id=document.id + ) transpo_dict[forum] = document return transpo_dict