From af29d3a7eb0dac8d46bed872b05502383d57e858 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 29 Jan 2015 00:17:28 +0100 Subject: Operation: put a default year from start_date --- archaeological_operations/models.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 5e3b05097..7d13669b1 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -416,6 +416,12 @@ class Operation(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem, return {'date':item.history_date, 'user':IshtarUser.objects.get(pk=item.history_modifier_id)} + def save(self, *args, **kwargs): + # put a default year if start_date is defined + if self.start_date and not self.year: + self.year = self.start_date.year + return super(Operation, self).save(*args, **kwargs) + m2m_changed.connect(cached_label_changed, sender=Operation.towns.through) def operation_post_save(sender, **kwargs): -- cgit v1.2.3