expirelinks.py 458 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
from django.core.management.base import BaseCommand
from django.utils import timezone
from go.models import URL


class Command(BaseCommand):
    help = 'Removes expired links from the database'

    def handle(self, *args, **options):
        for toexpire in URL.objects.filter(expires__lte=timezone.now()):
            self.stdout.write("Removed URL %s (%s), expires %s" % (toexpire.target, toexpire.short, toexpire.expires))
            toexpire.delete()