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.shortcuts import render, get_object_or_404
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
from django.db.models import Count
|
||||||
from hub.services.models import (
|
from hub.services.models import (
|
||||||
Service,
|
Service,
|
||||||
ServiceOffering,
|
ServiceOffering,
|
||||||
|
@ -47,14 +48,16 @@ def provider_detail(request, slug):
|
||||||
.prefetch_related("categories")
|
.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
|
# Exclude offerings with disabled services
|
||||||
ordered_offerings = (
|
ordered_offerings = (
|
||||||
ServiceOffering.objects.filter(
|
ServiceOffering.objects.filter(
|
||||||
cloud_provider=provider, service__disable_listing=False
|
cloud_provider=provider, service__disable_listing=False
|
||||||
)
|
)
|
||||||
.select_related("service")
|
.select_related("service")
|
||||||
|
.annotate(has_plans=Count("plans"))
|
||||||
.order_by(
|
.order_by(
|
||||||
|
"-has_plans", # Offerings with plans first
|
||||||
"-service__is_featured", # Featured first (True before False)
|
"-service__is_featured", # Featured first (True before False)
|
||||||
"service__is_coming_soon", # Coming soon last (False before True)
|
"service__is_coming_soon", # Coming soon last (False before True)
|
||||||
"service__name", # Alphabetically within each group
|
"service__name", # Alphabetically within each group
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue