<s> from __future__ import unicode_literals <EOL> from django . db import models , migrations <EOL> from django . db . models import Q <EOL> def update_event_attendance_from_tasks ( model , event ) : <EOL> """<STR_LIT>""" <EOL> learners = event . task_set . filter ( role__name = '<STR_LIT>' ) . count ( ) <EOL> model . objects . filter ( pk = event . pk ) . filter ( Q ( attendance__lt = learners ) | Q ( attendance__isnull = True ) ) . update ( attendance = learners ) <EOL> def update_attendance_for_historical_events ( apps , schema_editor ) : <EOL> """<STR_LIT>""" <EOL> Event = apps . get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> for event in Event . objects . all ( ) : <EOL> update_event_attendance_from_tasks ( Event , event ) <EOL> class Migration ( migrations . Migration ) : <EOL> dependencies = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] <EOL> operations = [ <EOL> migrations . RunPython ( update_attendance_for_historical_events ) , <EOL> ] </s>
