first commit
This commit is contained in:
16
accounts/tasks.py
Normal file
16
accounts/tasks.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from celery import shared_task
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.utils import timezone
|
||||
|
||||
|
||||
@shared_task(name='accounts.tasks.deactivate_expired_users_task')
|
||||
def deactivate_expired_users_task():
|
||||
"""Deactivate active users whose active_until timestamp has passed."""
|
||||
user_model = get_user_model()
|
||||
now = timezone.now()
|
||||
updated = user_model.objects.filter(
|
||||
is_active=True,
|
||||
active_until__isnull=False,
|
||||
active_until__lte=now,
|
||||
).update(is_active=False)
|
||||
return updated
|
||||
Reference in New Issue
Block a user