Tutorial by Examples

See this Q&A question if you don't know what race conditions are. The following code may be subject to race conditions : article = Article.objects.get(pk=69) article.views_count += 1 article.save() If views_count is equal to 1337, this will result in such query: UPDATE app_article SET vi...
Let's assume that we want to remove 2 upvotes from all the articles of the author with id 51. Doing this only with Python would execute N queries (N being the number of articles in the queryset): for article in Article.objects.filter(author_id=51): article.upvotes -= 2 article.save() ...
F() expressions can be used to execute arithmetic operations (+, -, * etc.) among model fields, in order to define an algebraic lookup/connection between them. Let model be: class MyModel(models.Model): int_1 = models.IntegerField() int_2 = models.IntegerField() Now lets assum...

Page 1 of 1