From 0d585824a02b3f7133e323d72bd1e778f9fa12ea Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 7 Jun 2024 17:41:03 +0200 Subject: 🗃️ Document: add cache_authors field (refs #5709) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations/0247_document_cached_authors.py | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 ishtar_common/migrations/0247_document_cached_authors.py (limited to 'ishtar_common/migrations') diff --git a/ishtar_common/migrations/0247_document_cached_authors.py b/ishtar_common/migrations/0247_document_cached_authors.py new file mode 100644 index 000000000..862dc036b --- /dev/null +++ b/ishtar_common/migrations/0247_document_cached_authors.py @@ -0,0 +1,37 @@ +# Generated by Django 2.2.24 on 2024-06-07 17:22 + +from django.db import migrations, models + + +def generate_cache_authors(apps, __): + Document = apps.get_model('ishtar_common', 'Document') + for doc in Document.objects.all(): + doc.cache_authors = " ; ".join([author.cached_label for author in doc.authors.all()]) + doc.skip_history_when_saving = True + doc.no_post_process() + doc.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('ishtar_common', '0246_profile_rel_engine_default_changed_to_cache_tables'), + ] + + operations = [ + migrations.AlterModelOptions( + name='jsondatasection', + options={'ordering': ['order', 'name'], 'verbose_name': 'Custom data - Section', 'verbose_name_plural': 'Custom data - Sections'}, + ), + migrations.AddField( + model_name='document', + name='cache_authors', + field=models.TextField(blank=True, db_index=True, default='', help_text='Cached value - do not edit', verbose_name='Authors'), + ), + migrations.AddField( + model_name='historicaldocument', + name='cache_authors', + field=models.TextField(blank=True, db_index=True, default='', help_text='Cached value - do not edit', verbose_name='Authors'), + ), + migrations.RunPython(generate_cache_authors) + ] -- cgit v1.2.3