I want to delete users that haven't activated their accounts when the activation token have expired, activation token expires after 30 minutes.
from django.db.models.functions import Now
def delete_unactivated_users():
User = get_user_model()
expiry = User.date_joined + timedelta(seconds=1800)
unactivated_users = User.objects.filter(Q(Now()__gt=expiry) & (Q(is_active = False)))
for user in unactivated_users:
user.delete()
print('<<<User Deleted>>>')
user.save
I am getting a syntax error on line 5 of the code, I tried using
unactivated_users = User.objects.filter(Q(expiry__lt=Now()) & (Q(is_active=False)))
but it didn't result in the same meaning. The problem seems to be the placing of Now()
and expiry
on line 5