Skip to content

Commit b8a1416

Browse files
committed
fix: filtering and sorting
1 parent 604c953 commit b8a1416

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

myapp/views.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,17 @@ def dashboard(request):
7373
'expired_items': expired_items,
7474
'shared_items_count_by_you': shared_items_count_by_you,
7575
'shared_items_count_with_you': shared_items_count_with_you,
76-
'container_version': settings.VERSION,
7776
}
7877
return render(request, 'dashboard.html', context)
7978

8079
@require_GET
8180
@login_required
8281
def show_items(request):
8382
user = request.user
83+
item_type = request.GET.get('type')
8484
filter_value = request.GET.get('status', 'available') # Get the combined filter value
8585
search_query = request.GET.get('query', '')
86-
86+
8787
# Base query
8888
if filter_value == 'shared_by_me':
8989
items = Item.objects.filter(shared_with__shared_by=user).distinct()
@@ -100,12 +100,21 @@ def show_items(request):
100100
elif filter_value == 'expired':
101101
items = items.filter(expiry_date__lt=timezone.now())
102102

103+
# Apply the item_type filter if provided
104+
if item_type:
105+
items = items.filter(type=item_type)
106+
107+
# Apply search query filter if provided
103108
if search_query:
104109
items = items.filter(
105110
Q(name__icontains=search_query) |
106111
Q(issuer__icontains=search_query)
107112
)
108113

114+
115+
# Sort by expiry date, soonest first
116+
items = items.order_by('expiry_date')
117+
109118
items_with_qr = []
110119

111120
for item in items:
@@ -121,10 +130,10 @@ def show_items(request):
121130

122131
context = {
123132
'items_with_qr': items_with_qr,
124-
'item_status': filter_value, # Reuse item_status to hold the combined filter value
133+
'item_type': item_type, # Add the item_type to the context
134+
'item_status': filter_value, # Reuse item_status to hold the combined filter value
125135
'search_query': search_query,
126136
'current_date': timezone.now(),
127-
'container_version': settings.VERSION,
128137
}
129138
return render(request, 'inventory.html', context)
130139

0 commit comments

Comments
 (0)