Cross-organizer acceptance

This commit is contained in:
Raphael Michel
2019-09-18 19:37:56 +02:00
parent c68f715e07
commit e37d85f517
3 changed files with 15 additions and 5 deletions

View File

@@ -2,6 +2,7 @@ import string
from django.core.validators import RegexValidator
from django.db import models
from django.db.models import Exists, OuterRef, Q
from django.utils.crypto import get_random_string
from django.utils.functional import cached_property
from django.utils.translation import ugettext_lazy as _
@@ -90,6 +91,16 @@ class Organizer(LoggedModel):
default=lambda: self.issued_gift_cards.exists() or self.gift_card_issuer_acceptance.exists()
)
@property
def accepted_gift_cards(self):
from .giftcards import GiftCard, GiftCardAcceptance
return GiftCard.objects.annotate(
accepted=Exists(GiftCardAcceptance.objects.filter(issuer=OuterRef('issuer'), collector=self))
).filter(
Q(issuer=self) | Q(accepted=True)
)
def allow_delete(self):
from . import Order, Invoice
return (