From 39236b45ebe40acf6706e56ed5725d285bf1d21e Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 17 Mar 2025 09:32:46 +0100 Subject: [PATCH] offerings with plans first on list --- hub/services/views/providers.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hub/services/views/providers.py b/hub/services/views/providers.py index ed35652..3e8b965 100644 --- a/hub/services/views/providers.py +++ b/hub/services/views/providers.py @@ -1,5 +1,6 @@ from django.shortcuts import render, get_object_or_404 from django.db.models import Q +from django.db.models import Count from hub.services.models import ( Service, ServiceOffering, @@ -47,14 +48,16 @@ def provider_detail(request, slug): .prefetch_related("categories") ) - # Get the provider's offerings and sort them by service attributes + # Get the provider's offerings and sort them by service attributes and plan availability # Exclude offerings with disabled services ordered_offerings = ( ServiceOffering.objects.filter( cloud_provider=provider, service__disable_listing=False ) .select_related("service") + .annotate(has_plans=Count("plans")) .order_by( + "-has_plans", # Offerings with plans first "-service__is_featured", # Featured first (True before False) "service__is_coming_soon", # Coming soon last (False before True) "service__name", # Alphabetically within each group