mirror of
https://github.com/django/django.git
synced 2025-09-26 12:09:19 +00:00
Fixed #2705: added a select_for_update()
clause to querysets.
A number of people worked on this patch over the years -- Hawkeye, Colin Grady, KBS, sakyamuni, anih, jdemoor, and Issak Kelly. Thanks to them all, and apologies if I missed anyone. Special thanks to Dan Fairs for picking it up again at the end and seeing this through to commit. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16058 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
99c1794427
commit
8f0f73c7b8
14 changed files with 375 additions and 0 deletions
|
@ -435,6 +435,7 @@ class QuerySet(object):
|
|||
del_query._for_write = True
|
||||
|
||||
# Disable non-supported fields.
|
||||
del_query.query.select_for_update = False
|
||||
del_query.query.select_related = False
|
||||
del_query.query.clear_ordering()
|
||||
|
||||
|
@ -583,6 +584,18 @@ class QuerySet(object):
|
|||
else:
|
||||
return self._filter_or_exclude(None, **filter_obj)
|
||||
|
||||
def select_for_update(self, **kwargs):
|
||||
"""
|
||||
Returns a new QuerySet instance that will select objects with a
|
||||
FOR UPDATE lock.
|
||||
"""
|
||||
# Default to false for nowait
|
||||
nowait = kwargs.pop('nowait', False)
|
||||
obj = self._clone()
|
||||
obj.query.select_for_update = True
|
||||
obj.query.select_for_update_nowait = nowait
|
||||
return obj
|
||||
|
||||
def select_related(self, *fields, **kwargs):
|
||||
"""
|
||||
Returns a new QuerySet instance that will select related objects.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue