grid
parent
886ef5c0e7
commit
cfadccdc1c
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.
Binary file not shown.
|
@ -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',
|
||||||
|
|
|
@ -59,9 +59,26 @@
|
||||||
|
|
||||||
<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 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>
|
</div>
|
||||||
<section>
|
<section>
|
||||||
{# <div class="container">#}
|
{# <div class="container">#}
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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,7 +10,11 @@ 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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue