mirror of https://github.com/django/django.git
Fixed #4427 -- Ported daily_cleanup.py to use model API for greater
portability. Thanks, nick.lane.au@gmail.com. git-svn-id: http://code.djangoproject.com/svn/django/trunk@5403 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
a3b6e4e7d3
commit
250b84dd0e
1
AUTHORS
1
AUTHORS
|
@ -142,6 +142,7 @@ answer newbie questions, and generally made Django that much better:
|
||||||
Joseph Kocherhans
|
Joseph Kocherhans
|
||||||
konrad@gwu.edu
|
konrad@gwu.edu
|
||||||
lakin.wecker@gmail.com
|
lakin.wecker@gmail.com
|
||||||
|
Nick Lane <nick.lane.au@gmail.com>
|
||||||
Stuart Langridge <http://www.kryogenix.org/>
|
Stuart Langridge <http://www.kryogenix.org/>
|
||||||
Nicola Larosa <nico@teknico.net>
|
Nicola Larosa <nico@teknico.net>
|
||||||
Eugene Lazutkin <http://lazutkin.com/blog/>
|
Eugene Lazutkin <http://lazutkin.com/blog/>
|
||||||
|
|
|
@ -7,13 +7,13 @@ Can be run as a cronjob to clean out old data from the database (only expired
|
||||||
sessions at the moment).
|
sessions at the moment).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from django.db import backend, connection, transaction
|
import datetime
|
||||||
|
from django.db import transaction
|
||||||
|
from django.contrib.sessions.models import Session
|
||||||
|
|
||||||
def clean_up():
|
def clean_up():
|
||||||
# Clean up old database records
|
"""Clean up expired sessions."""
|
||||||
cursor = connection.cursor()
|
Session.objects.filter(expire_date__lt=datetime.datetime.now()).delete()
|
||||||
cursor.execute("DELETE FROM %s WHERE %s < NOW()" % \
|
|
||||||
(backend.quote_name('django_session'), backend.quote_name('expire_date')))
|
|
||||||
transaction.commit_unless_managed()
|
transaction.commit_unless_managed()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue