diff options
-rw-r--r-- | archaeological_files/tests.py | 7 | ||||
-rw-r--r-- | ishtar_common/utils.py | 11 |
2 files changed, 12 insertions, 6 deletions
diff --git a/archaeological_files/tests.py b/archaeological_files/tests.py index 312204a14..ef6c5ad74 100644 --- a/archaeological_files/tests.py +++ b/archaeological_files/tests.py @@ -139,7 +139,12 @@ class FileTest(TestCase, FileInit): for k in initial_values.keys(): if k == 'last_modified': continue - self.assertTrue(k in new_values) + elif k == 'history_m2m' and not initial_values[k]: + initial_values[k] = dict( + [(j, []) for j in models.File.HISTORICAL_M2M] + ) + self.assertTrue(k in new_values, + msg=u'%s not in new values' % k) self.assertEqual( new_values[k], initial_values[k], msg=u"for %s: %s != %s" % (k, unicode(new_values[k]), diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index ba77a07e4..cbc7d069d 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -949,11 +949,12 @@ def m2m_historization_changed(sender, **kwargs): q = obj.history.filter( history_modifier_id=obj.history_modifier_id, ).order_by('-history_date', '-history_id') - hist = q.all()[0] - hist.history_m2m = hist_values - hist.history_date = hist.last_modified = datetime.datetime.now() - hist.save() - obj.skip_history_when_saving = True + if q.count(): + hist = q.all()[0] + hist.history_m2m = hist_values + hist.history_date = hist.last_modified = datetime.datetime.now() + hist.save() + obj.skip_history_when_saving = True elif not obj.history_modifier: obj.skip_history_when_saving = True obj.save() |