class DateTimeGteFilter(filters.IsoDateTimeFromToRangeFilter):
def filter(self, qs, value):
if value != None:
return qs.prefetch_related(
Prefetch(
'coincosts_set',
to_attr='filtered_costs',
queryset=CoinCosts.objects.filter(timestamp__gte=value)
)
)
else:
return qs
class CoinCostFilterSet(filters.FilterSet):
timestamp_start = DateTimeGteFilter()
class Meta:
model = Coins
fields = {
'symbol': ['exact'],
#'timestamp_start': ['gt', 'lt'],
}
class CoinCostViewSet(viewsets.ModelViewSet):
queryset = Coins.objects.all()
serializer_class = CoinSerializer
filter_backends = (filters.DjangoFilterBackend,)
filterset_class = CoinCostFilterSet
class CoinCostFilterSet(filters.FilterSet):
timestamp_start = DateTimeGteFilter()
class Meta:
model = Coins
fields = {
'symbol': ['exact'],
#'timestamp_start': ['gt', 'lt'],
}