def migrate(migrator, database, fake=False, **kwargs): if fake: return MalwareScan = migrator.orm["malware_scans"] MalwareHit = migrator.orm["malware_hits"] for scan in MalwareScan: total_malicious = ( scan.malwarehit_set.select().where(MalwareHit.malicious).count() ) scan.total_malicious = total_malicious scan.save() def rollback(migrator, database, fake=False, **kwargs): pass