mysql - use F for referencing 2 tables to update python -
hi have script use 2 or 3 tables referencing update data in database
below code
getteam = myteam.objects.only("id") # [:2] limits query 2 testing in getteam: gettraining = training.objects.get(teamid=i.id) # because traning table empty getprimary = gettraining.primary if getprimary == 1 or getprimary == 0 : getteamplayers = teamplayers.objects.filter(teamid=i.id) t in getteamplayers : getmyplayer= myplayer.objects.get(id=t.playerid) getplayerage = getmyplayer.age increase = max(0, (1+((midage - getplayerage) * multiplier) / 100) * 0.05 / 9) getvitals = vitals.objects.get(playerid=t.playerid) getvitals.velocity = min(max(getvitals.velocity + increase,0),1) getvitals.power = min(max(getvitals.power + increase,0),1) getvitals.arm = min(max(getvitals.arm + increase,0),1) getvitals.ranges = min(max(getvitals.ranges + increase,0),1) getvitals.save() print t.playerid
i running script on terminal , want use f class or update , because takes time update , can please suggest how can use or increase speed of insertion time
a dramatic performance boost given running update function in single transaction.
take @ django database transaction management details. consider use of django.db.transaction.commit_on_success can used context manager:
from django.db import transaction transaction.commit_on_success(): # code here
or function decorator:
from django.db import transaction @transaction.commit_on_success def update_function(): # code here
Comments
Post a Comment