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