summaryrefslogtreecommitdiff
path: root/archaeological_context_records/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2017-07-26 14:39:13 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2017-07-26 14:39:13 +0200
commit943a35dacc9fdd0e86cf4713c441124d99fafa14 (patch)
tree8b9cef16c3dc1077b81465029b102391fa6106fa /archaeological_context_records/models.py
parent9a7c3c036e1ae743c7ccc00cdc4c9e8499b8578e (diff)
parent32d85d8604fbdf67644a406e265372e3bb4c8657 (diff)
downloadIshtar-943a35dacc9fdd0e86cf4713c441124d99fafa14.tar.bz2
Ishtar-943a35dacc9fdd0e86cf4713c441124d99fafa14.zip
Merge branch 'master' into develop
Diffstat (limited to 'archaeological_context_records/models.py')
-rw-r--r--archaeological_context_records/models.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index 483d77883..6ebdb8033 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -76,6 +76,20 @@ class Dating(models.Model):
return unicode(self.period)
return u"%s (%s-%s)" % (self.period, start_date, end_date)
+ @classmethod
+ def fix_dating_association(cls, obj):
+ """
+ Fix redundant m2m dating association (usually after imports)
+ """
+ current_datings = []
+ for dating in obj.datings.order_by('pk').all():
+ key = (dating.period.pk, dating.start_date, dating.end_date,
+ dating.dating_type, dating.quality, dating.precise_dating)
+ if key not in current_datings:
+ current_datings.append(key)
+ continue
+ dating.delete()
+
class Unit(GeneralType):
order = models.IntegerField(_(u"Order"))
@@ -496,6 +510,12 @@ class ContextRecord(BulkUpdatedItem, BaseHistorizedItem, ImageModel, OwnPerms,
self.save()
return returned
+ def fix(self):
+ """
+ Fix redundant m2m dating association (usually after imports)
+ """
+ Dating.fix_dating_association(self)
+
post_save.connect(cached_label_changed, sender=ContextRecord)