Item page

This commit is contained in:
Mikan
2024-09-16 15:48:35 +03:00
parent 56ffb93719
commit 05ba6704df
2 changed files with 13 additions and 5 deletions

View File

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

View File

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