1 from django.db import migrations, models
4 def refresh_books(apps, schema_editor):
5 Book = apps.get_model('catalogue', 'Book')
6 TagRelation = apps.get_model('catalogue', 'TagRelation')
7 db_alias = schema_editor.connection.alias
8 for book in Book.objects.using(db_alias).all():
9 book.cached_author = ', '.join(
10 TagRelation.objects.filter(content_type__model='book', object_id=book.id, tag__category='author')
11 .values_list('tag__name', flat=True))
12 book.has_audience = 'audience' in book.get_extra_info_json()
16 class Migration(migrations.Migration):
19 ('catalogue', '0015_book_recommended'),
26 field=models.CharField(db_index=True, max_length=240, blank=True),
31 field=models.BooleanField(default=False),
33 migrations.RunPython(refresh_books, migrations.RunPython.noop),