Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
go
Commits
d325bdfc
Commit
d325bdfc
authored
Nov 16, 2016
by
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
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
go/go/management/commands/expirelinks.py
View file @
d325bdfc
# Django Imports
from
django.core.management.base
import
BaseCommand
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
):
# Define help text for this command
help
=
'Removes expired links from the database'
# The handle function handles the main component of the django-admin command
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
()):
# Delete the current URL
toexpire
.
delete
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment