3.4. Increment an Atomic CounterΒΆ
awstin.dynamodb.Attr.set()
can take expressions defining the new value.
from models import Movie
from awstin.dynamodb import DynamoDB
def increase_rating(title, year, rating_increase):
dynamodb = DynamoDB()
table = dynamodb[Movie]
response = table.update_item(
(year, title),
update_expression=Movie.info.rating.set(Movie.info.rating + rating_increase),
)
return response
if __name__ == "__main__":
update_response = increase_rating("The Big New Movie", 2015, 1)
print("Update movie succeeded:")
print(update_response.serialize())