Ticket #2705: for_update.diff

File for_update.diff, 1.5 KB (added by Hawkeye, 18 years ago)
  • django/db/models/query.py

     
    8888        self._offset = None          # OFFSET clause.
    8989        self._limit = None           # LIMIT clause.
    9090        self._result_cache = None
     91        self._for_update = False
    9192
    9293    ########################
    9394    # PYTHON MAGIC METHODS #
     
    372373    def distinct(self, true_or_false=True):
    373374        "Returns a new QuerySet instance with '_distinct' modified."
    374375        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)
    375380
    376381    def extra(self, select=None, where=None, params=None, tables=None):
    377382        assert self._limit is None and self._offset is None, \
     
    402407        c._tables = self._tables[:]
    403408        c._offset = self._offset
    404409        c._limit = self._limit
     410        c._for_update = self._for_update
    405411        c.__dict__.update(kwargs)
    406412        return c
    407413
     
    505511            sql.append("%s " % backend.get_limit_offset_sql(self._limit, self._offset))
    506512        else:
    507513            assert self._offset is None, "'offset' is not allowed without 'limit'"
     514           
     515        if self._for_update is True:
     516            sql.append("FOR UPDATE ")
    508517
    509518        return select, " ".join(sql), params
    510519
Back to Top