diff options
| -rw-r--r-- | archaeological_operations/migrations/0024_reinit_history_creator.py | 20 | 
1 files changed, 17 insertions, 3 deletions
| diff --git a/archaeological_operations/migrations/0024_reinit_history_creator.py b/archaeological_operations/migrations/0024_reinit_history_creator.py index 40292844b..8a6b1f819 100644 --- a/archaeological_operations/migrations/0024_reinit_history_creator.py +++ b/archaeological_operations/migrations/0024_reinit_history_creator.py @@ -14,12 +14,26 @@ class Migration(DataMigration):                          ).order_by('history_date', 'history_id')                  if not q.count():                      return -                hist_item = q.all()[0] -                creator_id = hist_item.history_modifier_id +                hist_items, idx = list(q.all()), 0 +                creator_id = None +                while not creator_id: +                    if len(hist_items) <= idx: +                        break +                    hist_item = hist_items[idx] +                    try: +                        creator = orm['auth.User'].objects.get( +                                        pk=hist_item.history_modifier_id) +                        creator_id = creator.pk +                    except: +                        pass +                    idx += 1 +                if not creator_id: +                    continue +                  item.history_creator_id = creator_id                  item.skip_history_when_saving = True                  item.save() -                for hist in q.all(): +                for hist in hist_items:                      hist.history_creator_id = creator_id                      hist.save() | 
