Show More
@@ -1,19 +1,19 b'' | |||
|
1 | 1 | from django.core.management import BaseCommand |
|
2 | 2 | from django.db import transaction |
|
3 | 3 | from django.db.models import Count |
|
4 | 4 | |
|
5 | 5 | from boards.models import Tag |
|
6 | 6 | |
|
7 | 7 | |
|
8 | 8 | __author__ = 'neko259' |
|
9 | 9 | |
|
10 | 10 | |
|
11 | 11 | class Command(BaseCommand): |
|
12 | 12 | help = 'Removed tags that have no threads' |
|
13 | 13 | |
|
14 | 14 | @transaction.atomic |
|
15 | 15 | def handle(self, *args, **options): |
|
16 | empty = Tag.objects.annotate(num_threads=Count('thread'))\ | |
|
16 | empty = Tag.objects.annotate(num_threads=Count('thread_tags'))\ | |
|
17 | 17 | .filter(num_threads=0).order_by('-required', 'name') |
|
18 | 18 | print('Removing {} empty tags'.format(empty.count())) |
|
19 | 19 | empty.delete() |
General Comments 0
You need to be logged in to leave comments.
Login now