diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-07-26 15:05:09 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-07-26 15:05:09 +0200 |
commit | 8801ab7b7e655d8b831e535381eeea8adc091989 (patch) | |
tree | fd1cfe512c94affdfae65e7ec3078648eabffbd7 /archaeological_context_records/models.py | |
parent | c42486f81b042d18b9cf825da9f35a83e00bc051 (diff) | |
parent | 005f3962ab8d0eef66de6dd335f619702107116a (diff) | |
download | Ishtar-8801ab7b7e655d8b831e535381eeea8adc091989.tar.bz2 Ishtar-8801ab7b7e655d8b831e535381eeea8adc091989.zip |
Merge branch 'master' into v0.9
Diffstat (limited to 'archaeological_context_records/models.py')
-rw-r--r-- | archaeological_context_records/models.py | 20 |
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) |