I am new in python. How can call function from another function. Here is an example :
class TSMTViewSet(viewsets.ModelViewSet):
queryset = Tsmt.objects.all()
serializer_class = TsmtSerializer
def RunNew2N3(fromempid,toempid,fromdate,todate,fromcscid='',tocscid=''):
cursor = connection.cursor()
try:
cursor.callproc('[dbo].[SPRUN]',[fromempid,toempid,fromdate,todate,fromcscid,tocscid])
finally:
cursor.close()
def create(self,request):
tsmt = request.data.get('tsmt')
tsmt['createby']="Admin"
tsmt['createdate']=datetime.datetime.now()
fromempid = tsmt['empid']
toempid = tsmt['empid']
fromdate = tsmt['tdate']
todate = tsmt['tdate']
serializer = TsmtSerializer(data=tsmt)
if serializer.is_valid():
tsmt_saved = serializer.save()
RunNew2N3(fromempid,toempid,fromdate,todate)
return Response({"result":"TSMT '{}' created successfully".format(tsmt_saved.tdate),"status":"success"})
else:
return Response({"result":"'{}'".format(serializer.errors),"status":"fail"})
I put the call function on top and why I can't call that.I got the error message
NameError: name 'RunNew2N3' is not defined
createtakes aselfargument butRunNew2N3does not. Please show the full code and how you're calling it.RunNew2N3andcreateinside TSMTViewSet? If not, why doescreatetakeself? If so, please fix the indentation and explain whyRunNew2N3does not takeself.