1

In my User Model, I have set the following fields:

is_deactivated = models.BooleanField(default=False)
deactivation_initiated = models.DateTimeField(null=True) 
deactivate_at = models.DateTimeField(null=True) 

Whenever any User interacts with anything on the App (clicking a button, refreshing a page, etc.), I would like to check whether is_deactivated is True. If it is True, then I would like to compare the current real-world time with the deactivate_at time.

If the deactivate_at time has passed. Then I would like to automatically log the user out, and set is_active=False for the user.

I am unsure of how to implement something like this.

Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
N T
  • 11
  • 1
  • Rather than using the `User` model, I would suggest using [django session](https://docs.djangoproject.com/en/4.1/topics/http/sessions/#django.contrib.sessions.backends.base.SessionBase.set_expiry). – ruddra Feb 10 '23 at 14:13
  • Also you can use middleware – A D Feb 10 '23 at 14:20
  • Hi, thank you for your responses. Could you please elaborate on how I could use Django session to solve my problem? I would like to make a user account inactive once their deactivate_at time has been reached. – N T Feb 10 '23 at 15:00

0 Answers0