diff --git a/app/event/models.py b/app/event/models.py index 8269534..d7bf0c2 100644 --- a/app/event/models.py +++ b/app/event/models.py @@ -32,31 +32,34 @@ class Event(models.Model): @property def display_date(self): - date = self.date.split(' ') - start = date[0].split('-') - if len(date) > 1: - end = date[1].split('-') - else: - end = start - end_only_month = False - start_only_month = False - while len(end) < 3: - end.append(1) - end_only_month = True - while len(start) < 3: - start.append(1) - start_only_month = True - start = [int(p) for p in start] - end = [int(p) for p in end] + if self.date: + date = self.date.split(' ') + start = date[0].split('-') + if len(date) > 1: + end = date[1].split('-') + else: + end = start + end_only_month = False + start_only_month = False + while len(end) < 3: + end.append(1) + end_only_month = True + while len(start) < 3: + start.append(1) + start_only_month = True + start = [int(p) for p in start] + end = [int(p) for p in end] - display_date = datetime(*start).strftime('%d %B, %Y') - if start_only_month: - display_date = ' '.join(display_date.split(' ')[1:]) - if end != start: - end_date = datetime(*end).strftime('%d %B, %Y') - if end_only_month: - end_date = ' '.join(end_date.split(' ')[1:]) - display_date += ' — ' + end_date + display_date = datetime(*start).strftime('%e %B, %Y') + if start_only_month: + display_date = ' '.join(display_date.split(' ')[1:]) + if end != start: + end_date = datetime(*end).strftime('%e %B, %Y') + if end_only_month: + end_date = ' '.join(end_date.split(' ')[1:]) + display_date += ' — ' + end_date + else: + display_date = '' return display_date def media_html(self):