blob: 9f22422e743305b719d048dd433fbf81580ba5f1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
"""fix_answer_counts management command
to run type (on the command line:)
python manage.py fix_answer_counts
"""
from django.core.management.base import NoArgsCommand
from django.db.models import signals
from askbot import models
class Command(NoArgsCommand):
"""Command class for "fix_answer_counts"
"""
def remove_save_signals(self):
"""removes signals on model pre-save and
post-save, so that there are no side-effects
besides actually updating the answer counts
"""
signals.pre_save.receivers = []
signals.post_save.receivers = []
def handle(self, *arguments, **options):
"""function that handles the command job
"""
self.remove_save_signals()
for thread in models.Thread.objects.all():
thread.update_answer_count()
|