2025-05-26 11:33:04 +02:00
|
|
|
"""
|
|
|
|
Admin classes for cloud providers and consulting partners
|
|
|
|
"""
|
|
|
|
|
|
|
|
from django.contrib import admin
|
|
|
|
from django.utils.html import format_html
|
2025-07-08 11:59:19 +02:00
|
|
|
from django import forms
|
2025-05-26 11:33:04 +02:00
|
|
|
from adminsortable2.admin import SortableAdminMixin
|
|
|
|
|
|
|
|
from ..models import CloudProvider, ConsultingPartner, ServiceOffering
|
2025-07-08 11:59:19 +02:00
|
|
|
from .widgets import ImageLibraryWidget
|
|
|
|
|
|
|
|
|
|
|
|
class CloudProviderAdminForm(forms.ModelForm):
|
|
|
|
"""Custom form for CloudProvider admin with image widget"""
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = CloudProvider
|
|
|
|
fields = "__all__"
|
|
|
|
widgets = {
|
2025-07-08 11:59:43 +02:00
|
|
|
"image_library": ImageLibraryWidget(),
|
2025-07-08 11:59:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class ConsultingPartnerAdminForm(forms.ModelForm):
|
|
|
|
"""Custom form for ConsultingPartner admin with image widget"""
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ConsultingPartner
|
|
|
|
fields = "__all__"
|
|
|
|
widgets = {
|
2025-07-08 11:59:43 +02:00
|
|
|
"image_library": ImageLibraryWidget(),
|
2025-07-08 11:59:19 +02:00
|
|
|
}
|
2025-05-26 11:33:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
class OfferingInline(admin.StackedInline):
|
|
|
|
"""Inline admin for ServiceOffering model"""
|
|
|
|
|
|
|
|
model = ServiceOffering
|
|
|
|
extra = 1
|
|
|
|
fieldsets = (
|
|
|
|
(
|
|
|
|
None,
|
|
|
|
{
|
|
|
|
"fields": (
|
|
|
|
"description",
|
|
|
|
"service",
|
|
|
|
"cloud_provider",
|
|
|
|
"offer_description",
|
|
|
|
)
|
|
|
|
},
|
|
|
|
),
|
|
|
|
)
|
|
|
|
show_change_link = True
|
|
|
|
|
|
|
|
|
|
|
|
@admin.register(CloudProvider)
|
|
|
|
class CloudProviderAdmin(SortableAdminMixin, admin.ModelAdmin):
|
|
|
|
"""Admin configuration for CloudProvider model"""
|
|
|
|
|
2025-07-08 11:59:19 +02:00
|
|
|
form = CloudProviderAdminForm
|
|
|
|
|
2025-05-26 11:33:04 +02:00
|
|
|
list_display = (
|
|
|
|
"name",
|
|
|
|
"slug",
|
|
|
|
"logo_preview",
|
|
|
|
"disable_listing",
|
|
|
|
"is_featured",
|
|
|
|
"order",
|
|
|
|
)
|
|
|
|
search_fields = ("name", "description")
|
|
|
|
prepopulated_fields = {"slug": ("name",)}
|
|
|
|
inlines = [OfferingInline]
|
|
|
|
ordering = ("order",)
|
|
|
|
|
2025-07-04 17:26:09 +02:00
|
|
|
fieldsets = (
|
|
|
|
(None, {"fields": ("name", "slug", "description", "order")}),
|
|
|
|
(
|
|
|
|
"Images",
|
|
|
|
{
|
2025-07-08 11:45:13 +02:00
|
|
|
"fields": ("image_library",),
|
|
|
|
"description": "Select an image from the Image Library.",
|
2025-07-04 17:26:09 +02:00
|
|
|
},
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"Contact Information",
|
|
|
|
{"fields": ("website", "linkedin", "phone", "email", "address")},
|
|
|
|
),
|
|
|
|
("Settings", {"fields": ("is_featured", "disable_listing")}),
|
|
|
|
)
|
|
|
|
|
2025-05-26 11:33:04 +02:00
|
|
|
def logo_preview(self, obj):
|
|
|
|
"""Display logo preview in admin list view"""
|
2025-07-04 17:26:09 +02:00
|
|
|
logo = obj.get_logo
|
|
|
|
if logo:
|
|
|
|
return format_html('<img src="{}" style="max-height: 50px;"/>', logo.url)
|
2025-05-26 11:33:04 +02:00
|
|
|
return "No logo"
|
|
|
|
|
|
|
|
logo_preview.short_description = "Logo"
|
|
|
|
|
|
|
|
|
|
|
|
@admin.register(ConsultingPartner)
|
|
|
|
class ConsultingPartnerAdmin(SortableAdminMixin, admin.ModelAdmin):
|
|
|
|
"""Admin configuration for ConsultingPartner model"""
|
|
|
|
|
2025-07-08 11:59:19 +02:00
|
|
|
form = ConsultingPartnerAdminForm
|
|
|
|
|
2025-05-26 11:33:04 +02:00
|
|
|
list_display = (
|
|
|
|
"name",
|
2025-07-11 10:52:44 +02:00
|
|
|
"category",
|
2025-05-26 11:33:04 +02:00
|
|
|
"website",
|
|
|
|
"logo_preview",
|
|
|
|
"disable_listing",
|
|
|
|
"is_featured",
|
|
|
|
"order",
|
|
|
|
)
|
|
|
|
search_fields = ("name", "description")
|
2025-07-11 10:52:44 +02:00
|
|
|
list_filter = ("category", "is_featured", "disable_listing")
|
2025-05-26 11:33:04 +02:00
|
|
|
prepopulated_fields = {"slug": ("name",)}
|
|
|
|
filter_horizontal = ("services", "cloud_providers")
|
|
|
|
ordering = ("order",)
|
|
|
|
|
2025-07-04 17:26:09 +02:00
|
|
|
fieldsets = (
|
2025-07-11 10:52:44 +02:00
|
|
|
(None, {"fields": ("name", "slug", "description", "category", "order")}),
|
2025-07-04 17:26:09 +02:00
|
|
|
(
|
|
|
|
"Images",
|
|
|
|
{
|
2025-07-08 11:45:13 +02:00
|
|
|
"fields": ("image_library",),
|
|
|
|
"description": "Select an image from the Image Library.",
|
2025-07-04 17:26:09 +02:00
|
|
|
},
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"Contact Information",
|
|
|
|
{"fields": ("website", "linkedin", "phone", "email", "address")},
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"Relations",
|
|
|
|
{"fields": ("services", "cloud_providers"), "classes": ("collapse",)},
|
|
|
|
),
|
|
|
|
("Settings", {"fields": ("is_featured", "disable_listing")}),
|
|
|
|
)
|
|
|
|
|
2025-05-26 11:33:04 +02:00
|
|
|
def logo_preview(self, obj):
|
|
|
|
"""Display logo preview in admin list view"""
|
2025-07-04 17:26:09 +02:00
|
|
|
logo = obj.get_logo
|
|
|
|
if logo:
|
|
|
|
return format_html('<img src="{}" style="max-height: 50px;"/>', logo.url)
|
2025-05-26 11:33:04 +02:00
|
|
|
return "No logo"
|
|
|
|
|
|
|
|
logo_preview.short_description = "Logo"
|