correct ordering of services in provider
This commit is contained in:
parent
9ce96674c0
commit
5bad139d03
3 changed files with 28 additions and 3 deletions
|
@ -2,6 +2,7 @@ from django.shortcuts import render, get_object_or_404
|
|||
from django.db.models import Q
|
||||
from hub.services.models import (
|
||||
Service,
|
||||
ServiceOffering,
|
||||
CloudProvider,
|
||||
)
|
||||
|
||||
|
@ -39,13 +40,30 @@ def provider_detail(request, slug):
|
|||
|
||||
# Get all services offered by this provider through offerings
|
||||
services = (
|
||||
Service.objects.filter(offerings__cloud_provider=provider)
|
||||
Service.objects.filter(
|
||||
offerings__cloud_provider=provider, disable_listing=False
|
||||
)
|
||||
.distinct()
|
||||
.prefetch_related("categories")
|
||||
)
|
||||
|
||||
# Get the provider's offerings and sort them by service attributes
|
||||
# Exclude offerings with disabled services
|
||||
ordered_offerings = (
|
||||
ServiceOffering.objects.filter(
|
||||
cloud_provider=provider, service__disable_listing=False
|
||||
)
|
||||
.select_related("service")
|
||||
.order_by(
|
||||
"-service__is_featured", # Featured first (True before False)
|
||||
"service__is_coming_soon", # Coming soon last (False before True)
|
||||
"service__name", # Alphabetically within each group
|
||||
)
|
||||
)
|
||||
|
||||
context = {
|
||||
"provider": provider,
|
||||
"services": services,
|
||||
"ordered_offerings": ordered_offerings,
|
||||
}
|
||||
return render(request, "services/provider_detail.html", context)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue