diff --git a/mainsite/context_processors.py b/mainsite/context_processors.py index edeb5d6..afe7647 100644 --- a/mainsite/context_processors.py +++ b/mainsite/context_processors.py @@ -5,7 +5,7 @@ from . import models def sidebar_years(req): avail_years = models.PublicationYear.objects.all() - publi_years = [year for year in avail_years if len(year.publis()) > 0] + publi_years = [year for year in avail_years if year.publis().count() > 0] num_special_publications = models.Publication.objects\ .filter(is_special=True).count() diff --git a/mainsite/models.py b/mainsite/models.py index a2cbf7a..522d786 100644 --- a/mainsite/models.py +++ b/mainsite/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.db.models import Q from django.db.models import DateField, \ CharField, \ BooleanField, \ @@ -84,6 +85,10 @@ class Publication(models.Model): return self.num return 'BOcal n°{}'.format(self.num) + @staticmethod + def latest(): + return Publication.objects.order_by('-date')[0] + class Meta: ordering = ['date'] @@ -111,6 +116,7 @@ class PublicationYear(models.Model): def publis(self): ''' List of publications from this year ''' return Publication.objects.filter( + Q(is_special=False) | Q(in_year_view_anyway=True), date__gte=self.beg(), date__lt=self.end())