empty JSON/queryset on endpoint

When I ask for the entries of my database the browser only shows me an JSON with empty curly braces inside. The amount of entries are correct tho. The programm seems to find the database and also filter it, but somehow it fails when trying to extract the data.

Something like
/flush/?devid=2&startdate=11/10/21&enddate=29/10/21&resolution=1
would give me this :
{
{}
}

my db columns are called: ID , DEVICE ID , time , temp and status.

maybe they should be called by the other names id and devid ? just noticed when I wrote this text.

this is my models.py

 from django.db import models 

 class Flush(models.Model): 
     id = models.AutoField(db_column = 'ID', primary_key = True) 
     devid = models.IntegerField(db_column = 'DEVICE ID',default = 0) 
     time = models.DateTimeField() 
     temp = models.IntegerField() 
     status = models.IntegerField() 
        class Meta:
            db_table = 'SpuKas'

this is my view in the views.py : there is some stuff that is not nessassary for this but the bug could be in there

 class FlushView(APIView,): 
    def get(self,request):
         devId = int(request.GET.get('devid', '1'))  
         startDate = datetime.strptime(request.GET.get('startdate', '01/01/00'), '%d/%m/%y') 
         endDate = datetime.strptime(request.GET.get('enddate', '01/01/00'), '%d/%m/%y') 
         resolution = int(request.GET.get('resolution', '1'))  
         queryset = Flush.objects.filter(devid=devId, time__range=(startDate, endDate + timedelta(days=1)))[0:18446744073709551615:resolution]  
          readSerializer = FlushSerializer(queryset, many = True) 
           return Response(readSerializer.data) 

serializers.py :

class FlushSerializer(serializers.Serializer):
    class Meta:
        model = Flush
        fields = '__all__'

For the sake of science, try counting the objects in your queryset with queryset.count() to find out if there is in fact any data in your queryset.

Also, debug by selecting the entire table with Flush.objects.all() and passing it to your serializer. By trying this you should be able to find out whether your query is to blame.

1 Like