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):
|
||||
return reverse('main:product_list_by_category',
|
||||
args=[self.slug])
|
||||
|
||||
class Product(models.Model):
|
||||
category = models.ForeignKey(Category,
|
||||
related_name='products',
|
||||
|
|
|
@ -59,9 +59,26 @@
|
|||
|
||||
<div id="header">
|
||||
<h3><img src="{% static "deps/favicon/favicon.ico.png"%}" alt="Логотип"> Nitaku shop</h3>
|
||||
|
||||
</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>
|
||||
{# <div class="container">#}
|
||||
|
|
|
@ -6,7 +6,7 @@ app_name = 'main'
|
|||
urlpatterns = [
|
||||
path('', views.index, name='index'),
|
||||
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,
|
||||
name='product_list_by_category'),
|
||||
path('<int:id>/<slug:slug>/', views.product_detail,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from django.shortcuts import render,get_object_or_404
|
||||
from django.http import HttpResponse
|
||||
from .models import Category, Product
|
||||
|
||||
def index(request) -> HttpResponse:
|
||||
context : dict = {
|
||||
'title':'Home',
|
||||
|
@ -9,9 +10,13 @@ def index(request) -> HttpResponse:
|
|||
'dict' : {'first':1},
|
||||
'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):
|
||||
context = {
|
||||
|
|
Loading…
Reference in New Issue