Commit a1f871c8 authored by Matheus Miranda's avatar Matheus Miranda
Browse files

Add user of iterator on queryset

parent 9c3c0fa8
...@@ -24,10 +24,8 @@ class Command(BaseCommand): ...@@ -24,10 +24,8 @@ class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
answered_actions_ids = Action.objects.filter(verb='answered').values_list('action_object_object_id', flat=True) answered_actions_ids = Action.objects.filter(verb='answered').values_list('action_object_object_id', flat=True)
counter = 0
# Create any missing Answer action # Create any missing Answer action
answers = Answer.objects.all() answers = Answer.objects.all().iterator()
for answer in answers: for answer in answers:
activity_id = answer.activity_id activity_id = answer.activity_id
...@@ -35,6 +33,7 @@ class Command(BaseCommand): ...@@ -35,6 +33,7 @@ class Command(BaseCommand):
verb = 'answered' verb = 'answered'
if str(answer.id) in answered_actions_ids: if str(answer.id) in answered_actions_ids:
print('Skipped for answer id:', answer.id)
continue continue
timesince = djtimesince(answer.timestamp).encode('utf8').replace(b'\xc2\xa0', b' ').decode('utf8') timesince = djtimesince(answer.timestamp).encode('utf8').replace(b'\xc2\xa0', b' ').decode('utf8')
...@@ -43,3 +42,5 @@ class Command(BaseCommand): ...@@ -43,3 +42,5 @@ class Command(BaseCommand):
action_obj = action_tuple[0][1] action_obj = action_tuple[0][1]
action_obj.timestamp = answer.timestamp action_obj.timestamp = answer.timestamp
action_obj.save() action_obj.save()
print("Creating action for answer id:", answer.id)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment