aboutsummaryrefslogtreecommitdiff
path: root/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'models.py')
-rw-r--r--models.py13
1 files changed, 2 insertions, 11 deletions
diff --git a/models.py b/models.py
index 3e48622..876160b 100644
--- a/models.py
+++ b/models.py
@@ -17,7 +17,7 @@
from django.db import connection, models
from django.db.models import Count, Manager, Q
from django.db.models.expressions import RawSQL
-from django.db.models.functions import Extract, ExtractYear
+from django.db.models.functions import ExtractWeek, ExtractYear
from django.utils.text import slugify
from .utils import parse_group
@@ -26,10 +26,6 @@ import hashlib
import os
-class ExtractWeek(Extract):
- lookup_name = "week"
-
-
class Timetable(models.Model):
name = models.CharField(max_length=64, unique=True, verbose_name="nom")
url = models.URLField(max_length=255, unique=True, verbose_name="URL")
@@ -137,12 +133,7 @@ class CourseManager(Manager):
return self.get_queryset().filter(Q(groups__td__isnull=True) | Q(groups__td=group.td), Q(groups__tp__isnull=True) | Q(groups__tp=group.tp), Q(groups__subgroup__isnull=True) | Q(groups__subgroup=group.subgroup), groups__mention=group.mention, timetable=group.timetable, **filters).order_by("begin")
def get_weeks(self, **criteria):
- qs = self.get_queryset().filter(**criteria).order_by("groups__name", "year", "week").annotate(_=Count(("groups", "year", "week", "begin")), year=ExtractYear("begin"))
-
- if connection.vendor == "postgresql":
- return qs.annotate(week=ExtractWeek("begin"))
- else:
- return qs.annotate(week=RawSQL("""cast(strftime("%%W", "begin") as integer)""", []))
+ return self.get_queryset().filter(**criteria).order_by("groups__name", "year", "week").annotate(_=Count(("groups", "year", "week", "begin")), year=ExtractYear("begin"), week=ExtractWeek("begin"))
class Course(models.Model):