def migrate_latest(records):
    for record in records:
        date = None
        for user, report in record.reports.iteritems():
            if date is None:
                date = report.get('date')
            elif date < report.get('date'):
                date = report.get('date')
        record.date_last_reported = date
        record.save()
        logger.info('Migrated date_last_reported for comment {}'.format(record._id))
dataset/ETHPy150Open CenterForOpenScience/osf.io/scripts/migrate_spam.py/migrate_latest/original