diff --git a/common/models.py b/common/models.py index a5ad032..09bd31e 100644 --- a/common/models.py +++ b/common/models.py @@ -73,12 +73,22 @@ class ItemData(models.Model): "updatedAt": self.updated_at.timestamp(), } + @property + def item_dict(self) -> typing.Dict[str, typing.Union[str, int, float, None]]: + return { + "image": self.image.url, + "title": self.title, + "shortDescription": self.short_description, + "description": self.description, + } + + @property def card_dict(self) -> typing.Dict[str, typing.Union[str, int, float, None]]: return { "id": self.id, "title": self.title, - "preview": self.preview + "preview": self.preview.url } @property @@ -93,6 +103,6 @@ class ItemData(models.Model): return { "id": self.id, "title": self.title, - "preview": self.preview + "preview": self.preview.url } diff --git a/common/views.py b/common/views.py index 04f3424..9b0b6ad 100644 --- a/common/views.py +++ b/common/views.py @@ -31,9 +31,7 @@ def get_cards(request: HttpRequest, variant: str, collection: str) -> HttpRespon def get_item(request: HttpRequest, collection: str, item_id: int) -> HttpResponse: try: item: ItemData = ItemData.objects.get(collection__name=collection, id=item_id) - return JsonResponse({ - 'item': item.dict - }) + return JsonResponse(item.item_dict) except Exception as e: if request.user.is_superuser: return HttpResponse(f"Произошла ошибка: {repr(e)}", status=500)