summaryrefslogtreecommitdiff
path: root/archaeological_context_records/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2017-07-24 19:34:27 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2017-07-24 19:37:02 +0200
commitc3b928b50cda4c087699fff50fd6e91dd75d2580 (patch)
treefb1c2133c08e1bdc3d1a087618c59776546ee266 /archaeological_context_records/models.py
parentbc959913ada31882c49bbfe510933edc9f043444 (diff)
downloadIshtar-c3b928b50cda4c087699fff50fd6e91dd75d2580.tar.bz2
Ishtar-c3b928b50cda4c087699fff50fd6e91dd75d2580.zip
Datings: post-fix of duplicates associated to the same object (usually on imports)
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 940330d86..a5f02133e 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -74,6 +74,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"))
@@ -493,6 +507,12 @@ class ContextRecord(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)