from django.db import migrations, models def keep_what_we_know(apps, schema_editor): """The continue point so far was the furthest place: it is that, and it was last saved at updated_at.""" EBookProgress = apps.get_model('books', 'EBookProgress') for p in EBookProgress.objects.all().iterator(): p.furthest_fraction = p.scroll_fraction p.furthest_anchor = p.position_anchor p.read_at = int(p.updated_at.timestamp() * 1000) p.save(update_fields=['furthest_fraction', 'furthest_anchor', 'read_at']) class Migration(migrations.Migration): dependencies = [ ('books', '0004_ebook_is_read'), ] operations = [ migrations.AddField( model_name='ebookprogress', name='read_at', field=models.BigIntegerField(blank=True, null=True), ), migrations.AddField( model_name='ebookprogress', name='device', field=models.CharField(blank=True, default='', max_length=40), ), migrations.AddField( model_name='ebookprogress', name='furthest_fraction', field=models.FloatField(default=0.0), ), migrations.AddField( model_name='ebookprogress', name='furthest_anchor', field=models.CharField(blank=True, default='', max_length=30), ), migrations.RunPython(keep_what_we_know, migrations.RunPython.noop), ]