You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
14 lines
601 B
14 lines
601 B
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)
|
|
|