Fix condition text and quantity text

Closes #3
Closes #4
This commit is contained in:
2026-01-25 06:11:37 -06:00
parent 6ab872e8f1
commit 11402d9964
4 changed files with 50 additions and 25 deletions

View File

@@ -4,6 +4,8 @@ from django.db.models import Q
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 .forms import SellerRegistrationForm, CardListingForm, PackListingForm, AddCardListingForm, SellerEditForm, BountyForm, BountyOfferForm, BulkListingForm
from django.utils.text import slugify
import random
@@ -19,6 +21,14 @@ def index(request):
def card_list(request):
cards = Card.objects.all().select_related('set', 'set__game').prefetch_related('listings')
# Annotate with total quantity of listed items
cards = cards.annotate(
total_quantity=Coalesce(
Sum('listings__quantity', filter=Q(listings__status='listed')),
Value(0)
)
)
# Filtering
game_slug = request.GET.get('game')
if game_slug:
@@ -43,7 +53,7 @@ def card_list(request):
hide_oos = 'on'
if hide_oos == 'on':
cards = cards.filter(listings__quantity__gt=0, listings__status='listed').distinct()
cards = cards.filter(total_quantity__gt=0)
# Simple logic: only show cards that have listings or show all?
# Let's show all for browsing, but indicate stock.