Improve price information
All checks were successful
Django CI/CD / test (push) Successful in 1m1s
Django CI/CD / build-and-push (push) Successful in 2m9s

This commit is contained in:
2025-01-30 16:38:13 +01:00
parent 4ec808eeec
commit 6f62889e92
10 changed files with 123 additions and 15 deletions

12
games/signals.py Normal file
View File

@ -0,0 +1,12 @@
from django.db.models.signals import m2m_changed
from django.dispatch import receiver
from django.utils.timezone import now
from games.models import Purchase
@receiver(m2m_changed, sender=Purchase.games.through)
def update_num_purchases(sender, instance, **kwargs):
instance.num_purchases = instance.games.count()
instance.updated_at = now()
instance.save(update_fields=["num_purchases"])