summaryrefslogtreecommitdiff
path: root/archaeological_context_records/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2017-07-26 15:06:40 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2017-07-26 15:06:40 +0200
commitd64dcad840e2dac9438eb054d86968e7f484008b (patch)
tree1fa9e1d51f84d6c03360f9e2cb62780dae604ec6 /archaeological_context_records/models.py
parent66b32cdb285d504212edbf43d5d2d425d659370a (diff)
parent8801ab7b7e655d8b831e535381eeea8adc091989 (diff)
downloadIshtar-d64dcad840e2dac9438eb054d86968e7f484008b.tar.bz2
Ishtar-d64dcad840e2dac9438eb054d86968e7f484008b.zip
Merge branch 'v0.9' into wheezy
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)