offerings with plans first on list

This commit is contained in:
Tobias Brunner 2025-03-17 09:32:46 +01:00
parent ad3f06d6ff
commit 39236b45eb
No known key found for this signature in database

View file

@ -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