bgneal@307: """ bgneal@307: forum_cleanup.py - A management command to cleanup forum model objects. Right bgneal@307: now this entails deleting old forum and topic last visit records. bgneal@307: bgneal@307: """ bgneal@307: import datetime bgneal@307: bgneal@595: from django.core.management.base import NoArgsCommand bgneal@307: bgneal@307: from forums.models import ForumLastVisit, TopicLastVisit bgneal@307: import forums.unread bgneal@307: bgneal@307: bgneal@307: class Command(NoArgsCommand): bgneal@307: help = "This command deletes old forum and topic last visit records." bgneal@307: bgneal@307: def handle_noargs(self, **opts): bgneal@307: bgneal@307: now = datetime.datetime.now() bgneal@307: threshold = now - forums.unread.THRESHOLD * 2 bgneal@307: bgneal@307: # delete old topic last visit records bgneal@307: TopicLastVisit.objects.filter(last_visit__lt=threshold).delete() bgneal@307: bgneal@307: # delete old forum visit records bgneal@307: ForumLastVisit.objects.filter(end_date__lt=threshold).delete()