pull/93/head
James Ramm 2017-09-29 19:00:37 +02:00 zatwierdzone przez GitHub
rodzic dcde8102a2
commit 966831f589
3 zmienionych plików z 25 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,25 @@
import datetime
from django.core.management import BaseCommand
from longclaw.longclawbasket.models import BasketItem
class Command(BaseCommand):
"""Remove old BasketItems.
This command can be used in conjunction with e.g. a cron job
to stop your database being polluted with abandoned basket items.
"""
help = "Remove baskets older than the given number of days"
def add_arguments(self, parser):
parser.add_argument('older_than_days', type=int)
# A command must define handle()
def handle(self, *args, **options):
days_old = options['older_than_days']
today = datetime.date.today()
date = today - datetime.timedelta(days=days_old)
qrs = BasketItem.objects.filter(date_added__lt=date)
count = qrs.count()
qrs.delete()
self.stdout.write(self.style.SUCCESS("Deleted {} basket items".format(count)))