correct ordering of services in provider

This commit is contained in:
Tobias Brunner 2025-03-17 09:18:54 +01:00
parent 9ce96674c0
commit 5bad139d03
No known key found for this signature in database
3 changed files with 28 additions and 3 deletions

View file

@ -101,7 +101,14 @@ class ExternalLinkInline(admin.TabularInline):
@admin.register(Service)
class ServiceAdmin(admin.ModelAdmin):
list_display = ("name", "logo_preview", "category_list", "partner_list")
list_display = (
"name",
"logo_preview",
"category_list",
"is_featured",
"is_coming_soon",
"disable_listing",
)
list_filter = ("categories",)
search_fields = ("name", "description", "slug")
prepopulated_fields = {"slug": ("name",)}

View file

@ -145,7 +145,7 @@
<div class="pt-40">
<h3 class="fs-24 fw-semibold lh-1 mb-12" id="services" style="scroll-margin-top: 100px;">Available Services</h3>
<div class="row">
{% for offering in provider.offerings.all %}
{% for offering in ordered_offerings %}
<div class="col-12 col-md-6 mb-30">
<div class="card h-100 d-flex flex-column">
{% if offering.service.logo or offering.service.is_featured %}

View file

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