Skip to content

Commit

Permalink
fix products list urls
Browse files Browse the repository at this point in the history
for #1
  • Loading branch information
ZendaInnocent committed Sep 14, 2023
1 parent ac0dba3 commit 6719436
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 75 deletions.
2 changes: 1 addition & 1 deletion main/templates/main/product_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{% block content %}
<h2 class="mb-3">Products</h2>

{% for product in object_list %}
{% for product in products %}
<p>{{ product.name }}</p>
<p>
<a href="{% url 'main:product-detail' product.slug %}">See it here</a>
Expand Down
64 changes: 0 additions & 64 deletions main/templates/main/tag_detail.html

This file was deleted.

1 change: 1 addition & 0 deletions main/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
path('', views.home_view, name='home'),
path('about/', views.about_view, name='about'),
path('contact/', views.ContactView.as_view(), name='contact'),
path('products/', views.ProductListView.as_view(), name='product-list'),
path('products/<slug:tag>/', views.ProductListView.as_view(), name='product-list'),
path(
'product/<slug:slug>/', views.ProductDetailView.as_view(), name='product-detail'
Expand Down
20 changes: 10 additions & 10 deletions main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,19 @@ def form_valid(self, form):
class ProductListView(generic.ListView):
template_name = 'main/product_list.html'
paginate_by = 6
context_object_name = 'products'

def get_queryset(self):
tag = self.kwargs['tag']
self.tag = None
tag = self.kwargs.get('tag', None)

if tag != 'all':
self.tag = get_object_or_404(ProductTag, slug=tag)
if tag is None:
return Product.objects.active().order_by('name')

if self.tag:
products = Product.objects.active().filter(tags=self.tag)
if tag == 'all':
return Product.objects.active()
else:
products = Product.objects.active()

return products.order_by('name')
tag: ProductTag = get_object_or_404(ProductTag, slug=tag)
return Product.objects.active().filter(tags=tag)


class ProductDetailView(generic.DetailView):
Expand All @@ -130,8 +129,9 @@ class ProductDetailView(generic.DetailView):


class TagDetailView(generic.ListView):
template_name = 'main/tag_detail.html'
template_name = 'main/product_list.html'
paginate_by = 6
context_object_name = 'products'

def get_queryset(self):
tag = self.kwargs['tag']
Expand Down

0 comments on commit 6719436

Please sign in to comment.