Reputation: 66
i need to migrate session data to the another table in database at the time of its destruction (for example, when the browser is closed or when expired date). I read that session doesn't clear itself , i need do it manualy .
Upvotes: 0
Views: 1112
Reputation: 33833
Django sessions are persisted to the db by default.
Read the docs:
https://docs.djangoproject.com/en/dev/topics/http/sessions/#configuring-the-session-engine
https://docs.djangoproject.com/en/dev/topics/http/sessions/#when-sessions-are-saved
https://docs.djangoproject.com/en/dev/topics/http/sessions/#clearing-the-session-store
Update:
The only situation where Django 'knows' the session has expired is when the user logs out manually. In this case you could connect to the user_logged_out
signal to do your data migration.
Otherwise the old session data stays in the db. Django provides the clearsessions
management command to delete old sessions. They suggest you run it daily on the crontab.
You could write your own version of that command which also does your data migration.
Upvotes: 1