File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ from django .core .management .base import BaseCommand
2+
3+ from api .models import Event
4+
5+
6+ class Command (BaseCommand ):
7+ help = "Update event sources based on name prefix and auto-generated status"
8+
9+ def handle (self , * args , ** options ):
10+ queryset = Event .objects .filter (auto_generated = True , source = 0 )
11+ self .stdout .write (
12+ self .style .NOTICE (
13+ f"{ queryset .count ()} events will be assigned a source (GDACS or Manual Input) based on name prefix."
14+ )
15+ )
16+ to_update = []
17+ for event in queryset .iterator ():
18+ if event .name .startswith ("GDACS" ):
19+ event .source = Event .EventSource .GDACS
20+ else :
21+ event .source = Event .EventSource .Manual_Input
22+ event .auto_generated = False
23+ to_update .append (event )
24+
25+ Event .objects .bulk_update (to_update , ["source" , "auto_generated" ])
26+ self .stdout .write (self .style .SUCCESS ("Event sources have been updated successfully." ))
You can’t perform that action at this time.
0 commit comments