Getting the amount of guests in bookings made django

后端 未结 2 2007
误落风尘
误落风尘 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: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 %}
    

提交回复
热议问题