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 Appeal , AppealType
4+ from dref .models import Dref
5+
6+
7+ class Command (BaseCommand ):
8+ help = "Migrate related Event to Dref"
9+
10+ def handle (self , * args , ** options ):
11+ self .stdout .write (self .style .NOTICE ("Starting migration of events to Dref..." ))
12+
13+ appeal_qs = Appeal .objects .filter (atype = AppealType .DREF ).exclude (code__isnull = True )
14+
15+ appeal_map = {appeal .code : appeal .event for appeal in appeal_qs if appeal .event }
16+
17+ drefs = Dref .objects .exclude (appeal_code__isnull = True )
18+ self .stdout .write (self .style .NOTICE (f"Total Dref records with appeal code:{ drefs .count ()} " ))
19+ count = 0
20+
21+ for dref in drefs :
22+ event_id = appeal_map .get (dref .appeal_code )
23+ if event_id :
24+ dref .event = event_id
25+ count += 1
26+
27+ Dref .objects .bulk_update (drefs , ["event" ])
28+ self .stdout .write (self .style .SUCCESS (f"Updated { count } Dref records with related Event" ))
You can’t perform that action at this time.
0 commit comments