<reponame>Danielvalev/django-ecommerce
from django.shortcuts import render, get_object_or_404
from .models import Category, Product


# Create your views here.

def product_all(request):
    products = Product.products.all()
    return render(request, 'store/home.html', {
        'products': products,
    })


def product_detail(request, slug):
    product = get_object_or_404(Product, slug=slug, in_stock=True)
    return render(request, 'store/products/single.html', {
        'product': product,
    })


def category_list(request, category_slug):
    category = get_object_or_404(Category, slug=category_slug)  # Return the category
    products = Product.objects.filter(category=category)  # Return all products with that category
    return render(request, 'store/products/category.html', {
        'category': category,
        'products': products,
    })

from django.shortcuts import render, get_object_or_404
from .models import Category, Product


# Create your views here.

def product_all(request):
    products = Product.products.all()
    return render(request, 'store/home.html', {
        'products': products,
    })


def product_detail(request, slug):
    product = get_object_or_404(Product, slug=slug, in_stock=True)
    return render(request, 'store/products/single.html', {
        'product': product,
    })


def category_list(request, category_slug):
    category = get_object_or_404(Category, slug=category_slug)  # Return the category
    products = Product.objects.filter(category=category)  # Return all products with that category
    return render(request, 'store/products/category.html', {
        'category': category,
        'products': products,
    })
# Create your views here. # Return the category # Return all products with that category