from datetime import date from .models import Hanchan, SeasonRanking from events.models import Event class MahjongMixin(object): def get_context_data(self, **kwargs): context = super(MahjongMixin, self).get_context_data(**kwargs) try: context['season'] = self.season context['season_start'] = date(year=self.season, month=1, day=1) context['season_end'] = date(year=self.season, month=12, day=31) context['season_list'] = SeasonRanking.objects.season_list except AttributeError: pass context['latest_hanchan_list'] = Hanchan.objects.confirmed()[:3] context['latest_event_list'] = Event.objects.latest(limit=3) return context