diff --git a/items/views.py b/items/views.py index ff9990d..6075175 100644 --- a/items/views.py +++ b/items/views.py @@ -14,6 +14,7 @@ from sales.models import ItemSale def list_items(request): page_query = request.GET.get('page', 1) mine_query = request.GET.get('mine') + avail_query = request.GET.get('avail') search_form = SearchItemForm(request.GET or None) # If the 'mine_query' query string is present, show the user's items @@ -25,10 +26,13 @@ def list_items(request): Q(name__icontains=search_form.cleaned_data.get('search')) | Q(whereabouts__icontains=search_form.cleaned_data.get('search')) | Q(description__icontains=search_form.cleaned_data.get('search')) - ) + ).order_by('-list_date') else: item_list = Item.objects.all().order_by('-list_date') + if avail_query: + item_list = item_list.filter(available=True).order_by('-list_date') + paginator = Paginator(item_list, 20) try: diff --git a/web/templates/items/list_items.html b/web/templates/items/list_items.html index 9b0b4dc..7424f70 100644 --- a/web/templates/items/list_items.html +++ b/web/templates/items/list_items.html @@ -8,6 +8,7 @@

View Items

{% if request.user.is_authenticated %} Your Items + Available Items All Items {% endif %}