diff options
Diffstat (limited to 'ishtar_common/utils_migrations.py')
| -rw-r--r-- | ishtar_common/utils_migrations.py | 24 | 
1 files changed, 24 insertions, 0 deletions
| 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() | 
