master
zacc806 2024-01-24 17:57:11 +06:00
parent 886ef5c0e7
commit cfadccdc1c
16 changed files with 35 additions and 12 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -18,6 +18,7 @@ class Category(models.Model):
def get_absolute_url(self): def get_absolute_url(self):
return reverse('main:product_list_by_category', return reverse('main:product_list_by_category',
args=[self.slug]) args=[self.slug])
class Product(models.Model): class Product(models.Model):
category = models.ForeignKey(Category, category = models.ForeignKey(Category,
related_name='products', related_name='products',

View File

@ -51,18 +51,35 @@
</div> </div>
</nav> </nav>
</header> </header>
<div class="container"> <div class="container">
<div class="row mt-1"> <div class="row mt-1">
<div class="col-lg-2"> <div class="col-lg-2">
<!-- Пустой блок на Ваше усмотрение --> <!-- Пустой блок на Ваше усмотрение -->
</div> </div>
<div id="header"> <div id="header">
<h3><img src="{% static "deps/favicon/favicon.ico.png"%}" alt="Логотип"> Nitaku shop</h3> <h3><img src="{% static "deps/favicon/favicon.ico.png"%}" alt="Логотип"> Nitaku shop</h3>
</div>
</div> </div>
</div> </div>
<div class="row"> <!-- Add this line -->
{% for product in products %}
<div class="col-6 col-md-4 p-4">
<div class="card border-primary rounded custom-shadow h-100">
<img src="{{ product.image.url }}" class="card-img-top img-fluid" alt={{ product.name }}>
<div class="card-body">
<a href="{{ product.get_absolute_url }}">
<p class="card-title">{{ product.name }}</p>
</a>
<p class="card-text text-truncate">{{ product.description }}</p>
<div class="d-flex justify-content-between">
<p><strong>{{ product.price }} $</strong></p>
</div>
</div>
</div>
</div>
{% endfor %}
</div> <!-- Add this line -->
</div>
<section> <section>
{# <div class="container">#} {# <div class="container">#}
{# <!-- Каталог и корзина с фиксированным расположением на странице -->#} {# <!-- Каталог и корзина с фиксированным расположением на странице -->#}

View File

@ -6,7 +6,7 @@ app_name = 'main'
urlpatterns = [ urlpatterns = [
path('', views.index, name='index'), path('', views.index, name='index'),
path('about/', views.about, name='about'), path('about/', views.about, name='about'),
path('', views.product_list, name='product_list'), path('products/', views.product_list, name='product_list'),
path('<slug:category_slug>/', views.product_list, path('<slug:category_slug>/', views.product_list,
name='product_list_by_category'), name='product_list_by_category'),
path('<int:id>/<slug:slug>/', views.product_detail, path('<int:id>/<slug:slug>/', views.product_detail,

View File

@ -1,6 +1,7 @@
from django.shortcuts import render,get_object_or_404 from django.shortcuts import render,get_object_or_404
from django.http import HttpResponse from django.http import HttpResponse
from .models import Category, Product from .models import Category, Product
def index(request) -> HttpResponse: def index(request) -> HttpResponse:
context : dict = { context : dict = {
'title':'Home', 'title':'Home',
@ -9,9 +10,13 @@ def index(request) -> HttpResponse:
'dict' : {'first':1}, 'dict' : {'first':1},
'is_authenticated':False 'is_authenticated':False
} }
products = Product.objects.all()
categories = Category.objects.all()
# Merge the two dictionaries into one
context.update({'products': products, 'categories': categories})
return render(request, 'main/index.html',context) return render(request, 'main/index.html', context)
def about(request): def about(request):
context = { context = {