Getting the amount of guests in bookings made django

后端 未结 2 2013
误落风尘
误落风尘 2021-01-23 02:29

If each a user goes into an event they can make an booking, but each event only has a certain amount of space open.

I would like to show in the event that there are 5 ou

相关标签:
2条回答
  • 2021-01-23 02:44

    if i correctly understand, you can try

    @property
    def bookings_total(self):
        return self.bookings_set.filter(bookingstatus='y').count()
    
    @property
    def bookings_left(self):
        return self.bookings_total - self.seats
    
    0 讨论(0)
  • 2021-01-23 02:53

    Try:

     events = Events.objects.filter(active='a').\
     filter(Q(date__gte=today)|Q(date=today)).order_by('date')
    
     events = events.filter(Q(booking__bookingstatus='n')|Q(booking__bookingstatus='p'))
     events = events.annotate(num_of_seats=Count('booking'))
    

    and now you can use, .num_of_seats to show no of seats in an event.

    In html file:

    {% for event in events %}
          {{event.title}}
          {{even.num_of_seats}}
    {% endfor %}
    
    0 讨论(0)
提交回复
热议问题