Features: 1) Add absolute URI resolution for image in Category and ProductImage.

Fixes: 1) Ensure fallback to empty string when `image` is None in `Category` and `ProductImage`.

Extra: Refactored `resolve_image` methods for improved URL handling.
This commit is contained in:
Egor Pavlovich Gorbunov 2025-11-12 12:53:28 +03:00
parent 59b09c40f6
commit 9632915593

View file

@ -235,7 +235,7 @@ class CategoryType(DjangoObjectType): # type: ignore [misc]
return result
def resolve_image(self: Category, info) -> str:
return self.image_url
return info.context.build_absolute_uri(self.image.url) if self.image else ""
def resolve_markup_percent(self: Category, info) -> float:
if info.context.user.has_perm("core.view_category"):
@ -466,8 +466,8 @@ class ProductImageType(DjangoObjectType): # type: ignore [misc]
filter_fields = ["uuid"]
description = _("product's images")
def resolve_image(self: ProductImage, _info):
return self.image_url
def resolve_image(self: ProductImage, info):
return info.context.build_absolute_uri(self.image.url) if self.image else ""
class ProductType(DjangoObjectType): # type: ignore [misc]