[Fixed]-Django not updating object in classmethod. Very strange

1👍

✅

When you save the address in the class method, it updates the object in the database, but not in the view.

You can call the refresh_from_db method to reload the values from the database.

if default.lower() == "true":        
    print "default is true"
    Address.set_default_address(address.id, address.client)  # updates the object in the db
    print address.default # will print False
    address.refresh_from_db()
    print address.default # will print True

See the docs on refreshing objects from the database for more details.

Leave a comment