Django filter events occurring today

前端 未结 6 713
伪装坚强ぢ
伪装坚强ぢ 2020-12-09 09:56

I\'m struggling to logically represent the following in a Django filter. I have an \'event\' model, and a location model, which can be represented as:

class          


        
6条回答
  •  执念已碎
    2020-12-09 10:44

    You need to use a range there like this:

    class EventManager(models.Manager):
        def bookings_today(self, location_id):
            from datetime import datetime
            now = datetime.now()
            bookings = self.filter(location=location_id, start__lte=now, end__gte=now)
            return bookings
    

提交回复
热议问题