Select (..)
FROM ActualTotalLoad
INNER JOIN ResolutionCode
ON ActualTotalLoad.resolutioncodeid = ResolutionCode.id
I have a uri : /areaname/resolutioncodetext/date
and I want to make the above query, so I can get the resolutioncodetext that is provided from this uri.
I tried Actualtotalload.objects.select_related()
but it excludes some columns .
Ask for anything extra you might need
models.py
class Areatypecode(models.Model):
id = models.AutoField(db_column='Id', primary_key=True) # Field name made lowercase.
entitycreatedat = models.DateTimeField(db_column='EntityCreatedAt') # Field name made lowercase.
entitymodifiedat = models.DateTimeField(db_column='EntityModifiedAt') # Field name made lowercase.
areatypecodetext = models.CharField(db_column='AreaTypeCodeText', max_length=255) # Field name made lowercase.
areatypecodenote = models.CharField(db_column='AreaTypeCodeNote', max_length=255) # Field name made lowercase.
class Actualtotalload(models.Model):
source = "entso-e"
dataset ="ActualTotalLoad"
actualtotalload_id = models.BigAutoField(db_column='Id', primary_key=True) # Field name made lowercase.
entitycreatedat = models.DateTimeField(db_column='EntityCreatedAt') # Field name made lowercase.
entitymodifiedat = models.DateTimeField(db_column='EntityModifiedAt') # Field name made lowercase.
actiontaskid = models.BigIntegerField(db_column='ActionTaskID') # Field name made lowercase.
status = models.CharField(db_column='Status', max_length=2, blank=True, null=True) # Field name made lowercase.
year = models.IntegerField(db_column='Year') # Field name made lowercase.
month = models.IntegerField(db_column='Month') # Field name made lowercase.
day = models.IntegerField(db_column='Day') # Field name made lowercase.
datetime = models.DateTimeField(db_column='DateTime') # Field name made lowercase.
areaname = models.CharField(db_column='AreaName', max_length=200, blank=True, null=True) # Field name made lowercase.
updatetime = models.DateTimeField(db_column='UpdateTime') # Field name made lowercase.
totalloadvalue = models.DecimalField(db_column='TotalLoadValue', max_digits=24, decimal_places=2) # Field name made lowercase.
areatypecodeid = models.ForeignKey(Allocatedeicdetail,db_column='AreaTypeCodeId', on_delete = models.CASCADE, blank=True, null=True) # Field name made lowercase.
mapcodeid = models.ForeignKey(Mapcode,on_delete = models.CASCADE, db_column='MapCodeId', blank=True, null=True) # Field name made lowercase.
areacodeid = models.ForeignKey(Areatypecode,related_name='areatypecode',on_delete = models.CASCADE, db_column='AreaCodeId') # Field name made lowercase.
resolutioncodeid = models.ForeignKey(Resolutioncode,on_delete = models.CASCADE,db_column='ResolutionCodeId', blank=True, null=True) # Field name made lowercase.
rowhash = models.CharField(db_column='RowHash', max_length=255, blank=True, null=True) # Field name made lowercase.
class Resolutioncode(models.Model):
id = models.AutoField(db_column='Id', primary_key=True) # Field name made lowercase.
entitycreatedat = models.DateTimeField(db_column='EntityCreatedAt') # Field name made lowercase.
entitymodifiedat = models.DateTimeField(db_column='EntityModifiedAt') # Field name made lowercase.
resolutioncodetext = models.CharField(db_column='ResolutionCodeText', unique=True, max_length=255) # Field name made lowercase.
resolutioncodenote = models.CharField(db_column='ResolutionCodeNote', max_length=255, blank=True, null=True) # Field name made lowercase.
The error that I get back from the api :
Exception Value: Cannot resolve keyword 'dataset' into field. Choices are: actiontaskid, actualtotalload_id, areacodeid, areacodeid_id, areaname, areatypecodeid, areatypecodeid_id, datetime, day, entitycreatedat, entitymodifiedat, mapcodeid, mapcodeid_id, month, resolutioncodeid, resolutioncodeid_id, rowhash, status, totalloadvalue, updatetime, year
from django.http import JsonResponse, HttpResponse
from .models import *
from RestApi.serializers import *
# Create your views here.
def ATL_for_date(request , AreaName = None , ResolutionCode = None , Date = None ):
Year = int ( Date [:4])
Month = int ( Date [5:7])
Day = int ( Date [8:])
AreaName = str(AreaName)
ResolutionCode = str(ResolutionCode)
Actualtotalload.objects.select_related()
queryset = list(Actualtotalload.objects.filter( areaname=AreaName , resolutioncodeid__resolutioncodetext= ResolutionCode, year = Year , month = Month , day = Day).values('source','dataset','areaname','areatype','mapcode','resolutioncodetext','year','month','day','datetime','totalloadvalue','updatetime'))
queryset.annotate(dataset=Value('ActualTotalLoad', output_field=CharField()))
queryset.annotate(source=Value('entso-e', output_field=CharField()))
return JsonResponse(queryset, safe = False)
Thank you in advance