Commit d325bdfc authored by David Haynes's avatar David Haynes
Browse files

Complete comments for expirelinks.py

 - fairly straightforward django-admin command
parent b88cdd89
Pipeline #467 passed with stage
in 7 minutes and 16 seconds
# Django Imports
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.utils import timezone from django.utils import timezone
from go.models import URL
# App Imports
from go.models import URL
# Define a new custom django-admin command
class Command(BaseCommand): class Command(BaseCommand):
# Define help text for this command
help = 'Removes expired links from the database' help = 'Removes expired links from the database'
# The handle function handles the main component of the django-admin command
def handle(self, *args, **options): def handle(self, *args, **options):
# Loop through a list of all URL objects that have expired
# (expires field is less than or equal to today's date)
for toexpire in URL.objects.filter(expires__lte=timezone.now()): for toexpire in URL.objects.filter(expires__lte=timezone.now()):
# Delete the current URL
toexpire.delete() toexpire.delete()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment