diff --git a/src/agenda_culturel/models.py b/src/agenda_culturel/models.py index a76f5db..8f63dfe 100644 --- a/src/agenda_culturel/models.py +++ b/src/agenda_culturel/models.py @@ -1071,7 +1071,9 @@ class Event(models.Model): .order_by("-score")[:10] ) - return qs.only("title", "start_day", "start_time", "exact_location", "location") + return qs.only( + "title", "start_day", "start_time", "exact_location", "location", "tags" + ) def proposed_events(self): threshold_distance = 30000 @@ -1106,15 +1108,22 @@ class Event(models.Model): ) else: qs = qs.annotate(overlap_tags_count=Value(1)) - qs = ( - qs.filter(overlap_tags_count__gte=min_tags) - .annotate( - distance=Distance( - F("exact_location__location"), self.exact_location.location + + if self.exact_location: + qs = ( + qs.filter(overlap_tags_count__gte=min_tags) + .annotate( + distance=Distance( + F("exact_location__location"), self.exact_location.location + ) ) + .filter(distance__lte=threshold_distance) ) - .filter(distance__lte=threshold_distance) - .annotate( + else: + qs = qs.annotate(distance=Value(1)) + + qs = ( + qs.annotate( nbday_distance=Func( (ExtractDay(F("start_day") - self.start_day)), function="ABS" ) @@ -1136,7 +1145,7 @@ class Event(models.Model): ) self._proposed_events = qs.only( - "title", "start_day", "start_time", "exact_location", "location" + "title", "start_day", "start_time", "exact_location", "location", "tags" ) self._proposed_events = sorted( self._proposed_events,