feat: MVP-скелет площадки (Django + MySQL/SQLite, модели по ТЗ §4, базовые страницы)
This commit is contained in:
1 parent
e5f312a00f
commit
8218a568ce
67 files changed
+1929
No files matched your search
@@ -0,0 +1,58 @@
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
|
||||
from apps.catalog.models import Brand, Category, ModerationStatus, Product
|
||||
from apps.content.models import Banner, Collection
|
||||
|
||||
PUBLISHED = ModerationStatus.PUBLISHED
|
||||
|
||||
|
||||
def home(request):
|
||||
banners = Banner.objects.filter(is_active=True)
|
||||
collections = Collection.objects.filter(is_published=True)
|
||||
products = Product.objects.filter(
|
||||
moderation_status=PUBLISHED, is_active=True,
|
||||
)[:8]
|
||||
return render(request, 'catalog/home.html', {
|
||||
'banners': banners,
|
||||
'collections': collections,
|
||||
'products': products,
|
||||
})
|
||||
|
||||
|
||||
def catalog(request):
|
||||
qs = Product.objects.filter(moderation_status=PUBLISHED, is_active=True)
|
||||
|
||||
current_category = None
|
||||
cat_slug = request.GET.get('category')
|
||||
if cat_slug:
|
||||
current_category = get_object_or_404(Category, slug=cat_slug)
|
||||
qs = qs.filter(category=current_category)
|
||||
|
||||
q = request.GET.get('q', '').strip()
|
||||
if q:
|
||||
qs = qs.filter(name__icontains=q)
|
||||
|
||||
categories = Category.objects.filter(parent__isnull=True)
|
||||
|
||||
return render(request, 'catalog/catalog.html', {
|
||||
'products': qs,
|
||||
'categories': categories,
|
||||
'current_category': current_category,
|
||||
'q': q,
|
||||
})
|
||||
|
||||
|
||||
def product_detail(request, slug):
|
||||
product = get_object_or_404(
|
||||
Product, slug=slug, moderation_status=PUBLISHED, is_active=True,
|
||||
)
|
||||
return render(request, 'catalog/product_detail.html', {'product': product})
|
||||
|
||||
|
||||
def brand_detail(request, slug):
|
||||
brand = get_object_or_404(Brand, slug=slug, verification_status='approved')
|
||||
products = brand.products.filter(moderation_status=PUBLISHED, is_active=True)
|
||||
return render(request, 'catalog/brand_detail.html', {
|
||||
'brand': brand,
|
||||
'products': products,
|
||||
})
|
||||
Reference in new issue
Block a user