[Fixed]-Raw Update Query inside a while loop in Django Python

1👍

You can try using Django ORM to query database.
Its very easy to understand.

def orprocesspost(request, pk):
  try:
     obj = or_details.objects.filter(orm_recno=pk)
     for i in obj:
        new_obj = general_ledger.objects.get(gl_code=i.xyz)  
        #xyz : name of your model field.
        newobj.dr_bal = newobj.dr_bal + <new value>
        newobj.cr_bal = newobj.cr_bal + <new value>
        newobj.save()

  exept or_details.DoesNotExist:
    print "object does not exist"

Leave a comment