Skip to content

Instantly share code, notes, and snippets.

@harshvb7
Last active September 13, 2018 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harshvb7/0554e1dd0980a73aa4bc8b8052741d6c to your computer and use it in GitHub Desktop.
Save harshvb7/0554e1dd0980a73aa4bc8b8052741d6c to your computer and use it in GitHub Desktop.
def get_reserved_tickets(self, performance=None):
Offer = apps.get_model('events', 'Offer')
Order = apps.get_model('events', 'Order')
offers = Offer.objects.published().filter(
state=1,
ticket_price=self,
)
if performance:
offers = offers.filter(performance=performance)
pending_tickets = offers.filter(basket__state=0).distinct() \
.aggregate(count=models.Sum('quantity'))['count']
pending_tickets = pending_tickets if pending_tickets else 0
booked_tickets = offers = offers.filter(basket__state=1) \
.values_list('basket_id', flat=True)
booked_tickets = Order.objects \
.filter(state=1, basket_id__in=list(booked_tickets)) \
.aggregate(count=models.Sum('tickets_count'))['count']
booked_tickets = booked_tickets if booked_tickets else 0
return pending_tickets + booked_tickets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment