diff options
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 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) |