Add rarity field to trade_offer instead of looking up via cards

This commit is contained in:
badblocks 2025-03-16 19:06:36 -07:00
parent ba33139993
commit f7a9b2f823
13 changed files with 87 additions and 50 deletions

View file

@ -1,4 +1,4 @@
# Generated by Django 5.1.2 on 2025-03-16 04:58
# Generated by Django 5.1.2 on 2025-03-16 18:18
import django.db.models.deletion
from django.db import migrations, models

View file

@ -6,11 +6,13 @@ register = template.Library()
@register.inclusion_tag("templatetags/card_badge.html")
def card_badge(card, quantity=1):
# Freeze the decks queryset once so that both the iteration and count use the same data
decks = list(card.decks.all()) if card else []
return {
'card': card,
'quantity': quantity,
'decks': card.decks.all() if card else None,
'num_decks': card.decks.count() if card else None,
'decks': decks,
'num_decks': len(decks),
}
@register.filter
@ -21,7 +23,7 @@ def card_badge_inline(card, quantity=1):
html = render_to_string("templatetags/card_badge.html", {
'card': card,
'quantity': quantity,
'decks': card.decks.all() if card else None,
'num_decks': card.decks.count() if card else None,
'decks': list(card.decks.all()) if card else [],
'num_decks': len(list(card.decks.all())) if card else 0,
})
return mark_safe(html)