diff --git a/src/agenda_culturel/calendar.py b/src/agenda_culturel/calendar.py index 137462a..c3dfe80 100644 --- a/src/agenda_culturel/calendar.py +++ b/src/agenda_culturel/calendar.py @@ -242,7 +242,7 @@ class CalendarList: Q(other_versions__isnull=True) | Q(other_versions__representative=F('pk')) | Q(other_versions__representative__isnull=True) - ).order_by("start_time", "title__unaccent__lower").prefetch_related("exact_location").prefetch_related("category").prefetch_related("other_versions").prefetch_related("other_versions__representative") + ).order_by("start_time", "title__unaccent__lower").select_related("exact_location").select_related("category").select_related("other_versions").select_related("other_versions__representative") firstdate = datetime.fromordinal(self.c_firstdate.toordinal()) if firstdate.tzinfo is None or firstdate.tzinfo.utcoffset(firstdate) is None: diff --git a/src/agenda_culturel/models.py b/src/agenda_culturel/models.py index d529e99..fb343c4 100644 --- a/src/agenda_culturel/models.py +++ b/src/agenda_culturel/models.py @@ -1978,7 +1978,7 @@ class CategorisationRule(models.Model): def get_category_from_rules(event): cats = defaultdict(lambda: 0) if CategorisationRule.rules is None: - CategorisationRule.rules = CategorisationRule.objects.all().prefetch_related("category").prefetch_related("place") + CategorisationRule.rules = CategorisationRule.objects.all().select_related("category").select_related("place") for rule in CategorisationRule.rules: if rule.match(event): diff --git a/src/agenda_culturel/views.py b/src/agenda_culturel/views.py index 66076d2..580968a 100644 --- a/src/agenda_culturel/views.py +++ b/src/agenda_culturel/views.py @@ -1492,7 +1492,7 @@ def set_duplicate(request, year, month, day, pk): @login_required(login_url="/accounts/login/") @permission_required("agenda_culturel.view_categorisationrule") def categorisation_rules(request): - paginator = Paginator(CategorisationRule.objects.all().order_by("pk").prefetch_related("category").prefetch_related("place"), 100) + paginator = Paginator(CategorisationRule.objects.all().order_by("pk").select_related("category").select_related("place"), 100) page = request.GET.get("page") try: @@ -1584,7 +1584,7 @@ def apply_categorisation_rules(request): else: # first we check if events are not correctly categorised to_categorise = [] - events = Event.objects.filter(start_day__gte=datetime.now()).exclude(category=Category.get_default_category_id()).exclude(category=None).prefetch_related("exact_location").prefetch_related("category") + events = Event.objects.filter(start_day__gte=datetime.now()).exclude(category=Category.get_default_category_id()).exclude(category=None).select_related("exact_location").select_related("category") for e in events: c = CategorisationRule.get_category_from_rules(e) if c and c != e.category: @@ -1593,7 +1593,7 @@ def apply_categorisation_rules(request): # then we apply rules on events without category nb = 0 to_save = [] - events = Event.objects.filter(start_day__gte=datetime.now()).filter(Q(category=Category.get_default_category_id()) | Q(category=None)).prefetch_related("exact_location").prefetch_related("category") + events = Event.objects.filter(start_day__gte=datetime.now()).filter(Q(category=Category.get_default_category_id()) | Q(category=None)).select_related("exact_location").select_related("category") for e in events: success = CategorisationRule.apply_rules(e) if success: