Fix card lookup for seller inventory

Closes #2
This commit is contained in:
2026-01-25 06:26:31 -06:00
parent eaa0fc03c4
commit 1cd87156bd
2 changed files with 231 additions and 2 deletions

View File

@@ -5,7 +5,7 @@ from django.core.paginator import Paginator
from django.contrib.auth.decorators import login_required
from .models import Card, Game, Set, Cart, CartItem, CardListing, PackListing, VirtualPack, Order, OrderItem, Seller, Bounty, BountyOffer, SellerReport
from django.db.models import Sum, Value
from django.db.models.functions import Coalesce
from django.db.models.functions import Coalesce, Length
from .forms import SellerRegistrationForm, CardListingForm, PackListingForm, AddCardListingForm, SellerEditForm, BountyForm, BountyOfferForm, BulkListingForm
from django.utils.text import slugify
import random
@@ -179,7 +179,12 @@ def card_autocomplete(request):
if len(query) < 2:
return JsonResponse({'results': []})
cards = Card.objects.filter(name__icontains=query).values_list('name', flat=True).distinct()[:10]
# Order by length to show shorter (likely more relevant) matches first
# Increase limit to 25 to avoid crowding out other games
cards = Card.objects.filter(name__icontains=query)\
.annotate(name_len=Length('name'))\
.order_by('name_len')\
.values_list('name', flat=True).distinct()[:25]
return JsonResponse({'results': list(cards)})
def bounty_autocomplete(request):