1 # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
4 from django.db import migrations, models
7 def refresh_books(apps, schema_editor):
8 Book = apps.get_model('catalogue', 'Book')
9 TagRelation = apps.get_model('catalogue', 'TagRelation')
10 db_alias = schema_editor.connection.alias
11 for book in Book.objects.using(db_alias).all():
12 book.cached_author = ', '.join(
13 TagRelation.objects.filter(content_type__model='book', object_id=book.id, tag__category='author')
14 .values_list('tag__name', flat=True))
15 book.has_audience = 'audience' in book.get_extra_info_json()
19 class Migration(migrations.Migration):
22 ('catalogue', '0015_book_recommended'),
29 field=models.CharField(db_index=True, max_length=240, blank=True),
34 field=models.BooleanField(default=False),
36 migrations.RunPython(refresh_books, migrations.RunPython.noop),