Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

HI i have a field in database whose value is null = true but i need to update it timely with the integers .I am running this script on terminal

getW =  get_HomeTeam_myworld.w  
getL =  get_HomeTeam_myworld.l  
if winloss == "w":
    getW = getW + 1 
    #getW.save()
    print getW

but it gives the following error

unsupported operand type(s) for +: 'NoneType' and 'int'

please suggest where i am doing mistake.

share|improve this question
add comment (requires an account with 50 reputation)

3 Answers

up vote 4 down vote accepted

It seems like getW value is None. Add some check:

if winloss == "w":
    getW = getW + 1 if getW else 1
    #getW.save()
    print getW
share|improve this answer
add comment (requires an account with 50 reputation)

ok i fix it actuality we need to save the object

get_HomeTeam_myworld.(save)
share|improve this answer
add comment (requires an account with 50 reputation)

tis is right can you also please tell me how can i save this update this value in db

this is the whole process

get_HomeTeam_myworld = myworld.objects.get(team_id=gethome_teamID)
    get_HomeTeam_myworld = myworld.objects.get(team_id=getaway_teamID)
    getW =  get_HomeTeam_myworld.w  
    getL =  get_HomeTeam_myworld.l  
    if winloss == "w":
        getW = getW + 1 if getW else 1
        getW.save() 
        print getW

it gives me the following error

'int' object has no attribute 'save'
share|improve this answer
get_HomeTeam_myworld.save() instead of getW.save() – Andrey Nelubin Aug 6 at 9:28
it doesnot throw any error but nothing is updated in db – Rohit Goel Aug 6 at 9:38
What prints myworld.objects.get(team_id=gethome_teamID).w after save? – Andrey Nelubin Aug 6 at 12:17
add comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.