# tasks.py from celery import shared_task from osinacore.models import * from django.db.models import Q @shared_task def set_offline(): print('Hello') all_staff_profiles = StaffProfile.objects.all() staff_without_working_points = all_staff_profiles.exclude( Q(task__point__status='Working On') ) users_without_working_points = [staff_profile.user for staff_profile in staff_without_working_points] print(users_without_working_points) # Create a new connection record for each user with status set to 'Offline' for user in users_without_working_points: Connection.objects.create( status='Offline', date=timezone.now(), user=user )