diff --git a/theme/management/commands/themeblog_to_blog.py b/theme/management/commands/themeblog_to_blog.py new file mode 100644 index 00000000..4a720ec9 --- /dev/null +++ b/theme/management/commands/themeblog_to_blog.py @@ -0,0 +1,14 @@ +from django.core.management.base import BaseCommand, CommandError +from theme.models import Theme, ThemeBlog +from article.models import Article + + +class Command(BaseCommand): + def handle(self, *args, **options): + for article in Article.objects.filter(type=Article.blog).prefetch_related('blog_theme'): + blogthemes = article.blog_theme.all().values_list('id', flat=True) + themes = Theme.objects.filter( + types=Theme.types.article, + blogtheme_linking_id__in=blogthemes) + article.theme.clear() + article.theme.add(*themes)