I want to apply a range filter on a timestamp field, based on query parameters start and end.
My view looks like this:
from rest_framework.generics import ListAPIView
from rest_framework.generics import RetrieveAPIView
from .models import HourlyTick
from .serializer import HourlyTickSerializer
# Create your views here.
class HourlyTickList(ListAPIView):
def get(self, request):
start = request.GET.get('start', None)
end = request.GET.get('end', None)
return HourlyTick.objects.filter(timestamp__range(start, end))
class HourlyTickDetail(RetrieveAPIView):
queryset = HourlyTick.objects.all()
serializer_class = HourlyTickSerializer
Model:
from django.db import models
# Create your models here.
class HourlyTick(models.Model):
id = models.IntegerField(primary_key=True)
timestamp = models.DateTimeField(blank=True, null=True)
symbol = models.TextField(blank=True, null=True)
open = models.IntegerField(blank=True, null=True)
high = models.IntegerField(blank=True, null=True)
low = models.IntegerField(blank=True, null=True)
close = models.IntegerField(blank=True, null=True)
trades = models.IntegerField(blank=True, null=True)
volume = models.IntegerField(blank=True, null=True)
vwap = models.FloatField(blank=True, null=True)
class Meta:
managed = False
db_table = 'xbtusd_hourly'
urls.py:
from django.urls import path, re_path
from . import views
urlpatterns = [
re_path('hourlyticks', views.HourlyTickList.as_view())
]
The error I receive is:
name 'timestamp__range' is not defined
What is the problem here?