[Answered ]-Django : delete multiple sessions without 'for loop'

2👍

The reason attempt 1 fails is basic Django query syntax: you must use __lt for comparisons:

Session.objects.filter(expire_date__lt=datetime.now()).delete()

Attempt 2 can never work, as the session model has no relationship with the user one.

Leave a comment