django date filter gte and lte

前端 未结 2 1842
-上瘾入骨i
-上瘾入骨i 2020-12-29 06:25

I need to find data within a certain set of parameters I am building a small booking system, that lets user see what vehicles are available for booking for their little safa

相关标签:
2条回答
  • 2020-12-29 07:00

    Could it be posible that as your passing the raw string to the queryset is not on the correct format, try converting the strings to datetime objects.

    Later you can try using the range lookup is more efficient on some DB engines and more simple to read and code.

    from django.db.models import Q
    
    start_date = datetime.date(2005, 1, 1)
    end_date = datetime.date(2005, 3, 31)
    orders = Order.objects.filter(drop_off__gte=start_date, pick_up__lte=end_date)
    # Or maybe better
    orders = Order.objects.filter(Q(drop_off__gte=start_date), Q(pick_up__lte=end_date))
    
    0 讨论(0)
  • 2020-12-29 07:03

    Can you try this :

    order = Order.objects.filter(pick_up**__date__**lte=pickup).filter(drop_off**__date__**gte=dropoff)
    

    https://docs.djangoproject.com/fr/2.0/ref/models/querysets/#date

    0 讨论(0)
提交回复
热议问题