offerings with plans first on list
This commit is contained in:
parent
ad3f06d6ff
commit
39236b45eb
1 changed files with 4 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue