Django filter events occurring today

前端 未结 6 709
伪装坚强ぢ
伪装坚强ぢ 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:34

    None of the answers I saw is timezone aware.

    Why don't you just do this instead:

    from django.utils import timezone
    
    class EventManager(models.Manager):
        def bookings_today(self, location_id):
            bookings = self.filter(location=location_id, start__gte=timezone.now().replace(hour=0, minute=0, second=0), end__lte=timezone.now().replace(hour=23, minute=59, second=59))
    

提交回复
热议问题