0

django-rest-framework如何使用大於篩選器篩選datetimefieldDjango rest框架按日期時間字段篩選

class RestaurantList(generics.ListAPIView): 
    serializer_class = RestaurantSerializer 

    def get_queryset(self): 
     #This returns equals but if I use the > sign it does not work 
     return Restaurant.objects.filter(last_update_time = "2016-08-03") 

回答

1

您可以使用gt聲明是這樣的:

def get_queryset(self): 
    return Restaurant.objects.filter(last_update_time__gt=datetime(2016, 08, 03) 

欲瞭解更多信息,請參閱doc