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