Skip to content

Instantly share code, notes, and snippets.

@susmithagudapati
Created April 27, 2020 17:57
Show Gist options
  • Save susmithagudapati/39733a07f2894cd27b611f54b04192b0 to your computer and use it in GitHub Desktop.
Save susmithagudapati/39733a07f2894cd27b611f54b04192b0 to your computer and use it in GitHub Desktop.
# Python's implementation
products = Product.objects.filter(category__name='shoes')
for product in products:
product.stock += 5
product.save()
# SQL incrementing using F() method.
Product.objects.filter(category__name='shoes').update(stock=F('stock') + 5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment