lib.itmens/users/management/commands/refresh_following.py

22 lines
567 B
Python
Raw Normal View History

2022-05-30 17:54:35 -04:00
from datetime import timedelta
from django.core.management.base import BaseCommand
2022-05-30 17:54:35 -04:00
from django.utils import timezone
from tqdm import tqdm
from users.models import User
2022-05-30 17:54:35 -04:00
class Command(BaseCommand):
2023-01-11 19:11:31 -05:00
help = "Refresh following data for all users"
2022-05-30 17:54:35 -04:00
def handle(self, *args, **options):
count = 0
for user in tqdm(User.objects.all()):
2023-08-11 01:43:19 -04:00
user.following = user.merged_following_ids()
2022-05-30 17:54:35 -04:00
if user.following:
count += 1
2023-01-11 19:11:31 -05:00
user.save(update_fields=["following"])
2022-05-30 17:54:35 -04:00
2023-01-11 19:11:31 -05:00
print(f"{count} users updated")