What is the advantage of Product.objects.update(stock=F('stock') - 1) over reading, changing and saving in Python?
A
It skips the database and edits a cache
B
The database updates it atomically
Correct answer
C
It works only when DEBUG is set to True
D
It loads every product into memory first
Correct answer
B. The database updates it atomically
13 views
⚔️
Challenge a friend on Django
Same MCQs, timed, live leaderboard. Send the link on WhatsApp – no sign-up needed.
Create challenge
Explanation
F() expressions reference field values inside the database, so the SQL is UPDATE … SET stock = stock − 1. Concurrent requests cannot overwrite each other's changes.
Reference
Asked in: Python Developer Interviews
Doubts & discussionNot sure why the answer is B? Ask here and get an explanation.
Ask a doubt about this MCQ
‹ Previous MCQ Which Django signal can run code automatically after a model instance is saved? Next MCQ › Which database does a new Django project use by default?