From 54c7aa355f235e6fee2ffe80707b072da5920963 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 16 Jan 2019 12:18:45 +0100 Subject: Recreate historical M2M --- ishtar_common/utils_migrations.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'ishtar_common/utils_migrations.py') diff --git a/ishtar_common/utils_migrations.py b/ishtar_common/utils_migrations.py index d161c1f29..edbeb5567 100644 --- a/ishtar_common/utils_migrations.py +++ b/ishtar_common/utils_migrations.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals +import datetime + from django.core.files import File import os @@ -112,3 +114,25 @@ def migrate_main_image(apps, app_name, model_name): item.skip_history_when_saving = True item.save() + +def m2m_historization_init(obj): + hist_values = obj.history_m2m or {} + for attr in obj.HISTORICAL_M2M: + values = [] + for value in getattr(obj, attr).all(): + if not hasattr(value, "history_compress"): + continue + values.append(value.history_compress()) + hist_values[attr] = values + obj.history_m2m = hist_values + for hist in obj.history.all(): + hist.history_m2m = hist_values + d = hist.history_date + date = datetime.datetime(year=d.year, month=d.month, day=d.day, + hour=d.hour, minute=d.minute, second=d.second, + microsecond=d.microsecond) + hist.history_date = date + hist.last_modified = date + hist.save() + obj.skip_history_when_saving = True + obj.save() -- cgit v1.2.3