From e98b1dc6156eda6261e158f02868d9f8d51b2913 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 17 Oct 2018 17:33:30 +0200 Subject: Find: search last modified and modified by --- ishtar_common/utils_migrations.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'ishtar_common/utils_migrations.py') diff --git a/ishtar_common/utils_migrations.py b/ishtar_common/utils_migrations.py index 48e9e4f9b..40cdcb5cd 100644 --- a/ishtar_common/utils_migrations.py +++ b/ishtar_common/utils_migrations.py @@ -75,3 +75,25 @@ def migrate_sources(apps, base_model, source_model, item_attr): doc.authors.add(author) item = base_model.objects.get(pk=getattr(source, item_attr).pk) item.documents.add(doc) + + +def reinit_last_modified(apps, app_name, models): + for model_name in models: + model = apps.get_model(app_name, model_name) + try: + historical_model = apps.get_model( + app_name, 'Historical' + model_name) + except: + continue + for item in model.objects.all(): + q = historical_model.objects.filter( + id=item.pk).order_by('-history_date') + if not q.count(): + return + edit_date = q.all()[0].history_date + if not edit_date: + return + item.last_modified = edit_date + item.skip_history_when_saving = True + item.save() + -- cgit v1.2.3