Files
santeh-ray/items/views.py
Azimkin 921cea9044
All checks were successful
Build and Push Docker Image / build (push) Successful in 24s
feat: add sidebar and item list to catalog page, enable DEBUG mode for development
- Created `side-bar.html` and `item-list.html` fragments for catalog page layout
- Updated `catalog/index.html` to include sidebar and item list templates
- Added styles for catalog layout in `catalog.css`
- Enabled `DEBUG=True` in settings for local development
- Adjusted CSS in shipping and services for consistent spacing
2026-04-07 23:09:19 +02:00

31 lines
862 B
Python

from dataclasses import dataclass
from django.http import HttpRequest, HttpResponse, Http404
from django.shortcuts import render, redirect
from items.models import Category, Item
# Create your views here.
@dataclass
class SelectedCategory:
name: str | None
id: str | None
def index(request: HttpRequest, category: str | None = None) -> HttpResponse:
selected_category = SelectedCategory(name=None, id=None)
if category is not None:
try:
cat = Category.objects.get(slug=category.lower())
selected_category = SelectedCategory(name=cat.name, id=cat.slug)
except Category.DoesNotExist:
raise Http404()
return render(request, 'catalog/index.html', {
'categories': Category.objects.all(),
'items': Item.objects.all(),
'selected_category': selected_category
})