Ticket #2705: for_update.diff
File for_update.diff, 1.5 KB (added by , 18 years ago) |
---|
-
django/db/models/query.py
88 88 self._offset = None # OFFSET clause. 89 89 self._limit = None # LIMIT clause. 90 90 self._result_cache = None 91 self._for_update = False 91 92 92 93 ######################## 93 94 # PYTHON MAGIC METHODS # … … 372 373 def distinct(self, true_or_false=True): 373 374 "Returns a new QuerySet instance with '_distinct' modified." 374 375 return self._clone(_distinct=true_or_false) 376 377 def for_update(self, update=True): 378 assert update is True or update is False 379 return self._clone(_for_update=update) 375 380 376 381 def extra(self, select=None, where=None, params=None, tables=None): 377 382 assert self._limit is None and self._offset is None, \ … … 402 407 c._tables = self._tables[:] 403 408 c._offset = self._offset 404 409 c._limit = self._limit 410 c._for_update = self._for_update 405 411 c.__dict__.update(kwargs) 406 412 return c 407 413 … … 505 511 sql.append("%s " % backend.get_limit_offset_sql(self._limit, self._offset)) 506 512 else: 507 513 assert self._offset is None, "'offset' is not allowed without 'limit'" 514 515 if self._for_update is True: 516 sql.append("FOR UPDATE ") 508 517 509 518 return select, " ".join(sql), params 510 519