Ticket #4427: daily_cleanup.3.patch
File daily_cleanup.3.patch, 850 bytes (added by , 17 years ago) |
---|
-
django/bin/daily_cleanup.py
7 7 sessions at the moment). 8 8 """ 9 9 10 from django.db import backend, connection, transaction 10 import datetime 11 from django.db import transaction 12 from django.contrib.sessions.models import Session 13 11 14 12 15 def clean_up(): 13 # Clean up old database records 14 cursor = connection.cursor() 15 cursor.execute("DELETE FROM %s WHERE %s < NOW()" % \ 16 (backend.quote_name('django_session'), backend.quote_name('expire_date'))) 16 # Clean up expired sessions. 17 Session.objects.filter(expire_date__lt=datetime.datetime.now()).delete() 17 18 transaction.commit_unless_managed() 18 19 19 20 if __name__ == "__main__":