Skip to content

Commit

Permalink
feat: add basic categories sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasFASouza committed Feb 3, 2023
1 parent 836c20d commit bacad3b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ Complete the implementation of your auction site. You must fulfill the following
- [x] If a user is signed in on a closed listing page, and the user has won that auction, the page should say so.
- [x] Users who are signed in should be able to add comments to the listing page. The listing page should display all comments that have been made on the listing.
- [ ] Watchlist: Users who are signed in should be able to visit a Watchlist page, which should display all of the listings that a user has added to their watchlist. Clicking on any of those listings should take the user to that listing’s page.
- [ ] Categories: Users should be able to visit a page that displays a list of all listing categories. Clicking on the name of any category should take the user to a page that displays all of the active listings in that category.
- [x] Categories: Users should be able to visit a page that displays a list of all listing categories. Clicking on the name of any category should take the user to a page that displays all of the active listings in that category.
- [x] Django Admin Interface: Via the Django admin interface, a site administrator should be able to view, add, edit, and delete any listings, comments, and bids made on the site.
19 changes: 19 additions & 0 deletions auctions/templates/auctions/categories.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends "auctions/layout.html" %}

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

<ul>
{% for listing in listings %}
{% if listing.category == category and listing.active %}
<li>
<img src="{{ listing.photo_url }}" width="128">
<div>
<a href="{% url 'listing' listing.id %}">{{ listing.title }}:</a>
{{ listing.description }}, by {{ listing.seller }} - $ {{ listing.price }}
</div>
</li>
{% endif %}
{% endfor %}
</ul>
{% endblock %}
18 changes: 18 additions & 0 deletions auctions/templates/auctions/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@
</li>
{% endif %}
</ul>
<h6>Categories</h6>
<ul class="nav">
<li class="nav-item">
<a class="nav-link" href="{% url 'categories' 'Fashion' %}">Fashion</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'categories' 'Home' %}">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'categories' 'Fashion' %}">Fashion</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'categories' 'Electronics' %}">Electronics</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'categories' 'Other' %}">Other</a>
</li>
</ul>
<hr>
{% block body %}
{% endblock %}
Expand Down
1 change: 1 addition & 0 deletions auctions/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
path("add", views.add_listing, name="add"),
path("<int:listing_id>", views.listing, name="listing"),
path("<int:listing_id>/close", views.close_auction, name="close"),
path("categories/<str:category>", views.categories, name="categories"),
]
7 changes: 7 additions & 0 deletions auctions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,10 @@ def close_auction(request, listing_id):
auction.save()

return HttpResponseRedirect(reverse("listing", kwargs={'listing_id': listing_id}))


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

0 comments on commit bacad3b

Please sign in to comment.