Item page
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user