How to delete latest record if it is matched with today date in django

I want to delete the record if it is matched with today's date and new record should replace with old record if it matches

I wrote code like below but it's not deleting the record new record also adding

Def addEscalatedcount(request):
dataDict=Helix.fectEscalted()
ifdataDict['error']==False:
 ESC=Escalated_count.object.all()
If ESC:
    recdate=ESC[0]
    if str(recdate.last_run.date)[0:10]==str(datetime.date.today())[0:10]:
    Escalated_count.get(id=recdate.id). delete ()
        ESC=addEscalatedSerializer(data=dataDict['data'],many=True)
 if ESC.is_valid():
   ESC.save()
   return jsonResponce("data saved",safe=False)
Back to Top