Skip to content

Commit

Permalink
Added category listings view
Browse files Browse the repository at this point in the history
  • Loading branch information
Ekaterina-Vititneva committed Aug 10, 2024
1 parent 05496fa commit 548483e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{% extends "auctions/layout.html" %}

{% block body %}
<h2> {{ category }} </h2>


<div class="listings-grid">
{% for listing in listings %}
<a class="listing-card-link" href="{% url 'listing' listing.title %}">
<div class="card" style="width: 18rem;">
{% if listing.imageURL %}
<img src= "{{ listing.imageURL }}" alt="listing image" height="200" class="listing-image">
{% else %}
<div class="placeholder-rectangle"></div>
{% endif %}
<div class="card-body">
<h5 class="card-title">{{ listing.title }}</h5>
<h6 class="card-subtitle mb-2 text-body">Price: {{ listing.bid }}€</h6>
<p class="card-text">{{ listing.description }}</p>
</div>
<div class="card-footer text-body-secondary">
<div>Created time: {{ listing.created_at }}</div>
</div>
</div>
</a>
{% endfor %}
</div>
{% endblock %}
6 changes: 4 additions & 2 deletions project_2/commerce/auctions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,10 @@ def categories(request):
})

def category_listings(request, category):
return render(request, "auctions/categories.html", {
"listings": Listing.objects.all()
category_listings = Listing.objects.filter(category=category)
return render(request, "auctions/category_listings.html", {
"category": category,
"listings": category_listings
})

def watchlist(request):
Expand Down

0 comments on commit 548483e

Please sign in to comment.