MCPcopy
hub / github.com/django/django / _update

Method _update

django/db/models/query.py:1409–1425  ·  view source on GitHub ↗

A version of update() that accepts field objects instead of field names. Used primarily for model saving and not intended for use by general code (it requires too much poking around at model internals to be useful at that level).

(self, values, returning_fields=None)

Source from the content-addressed store, hash-verified

1407 aupdate.alters_data = True
1408
1409 def _update(self, values, returning_fields=None):
1410 """
1411 A version of update() that accepts field objects instead of field
1412 names. Used primarily for model saving and not intended for use by
1413 general code (it requires too much poking around at model internals to
1414 be useful at that level).
1415 """
1416 if self.query.is_sliced:
1417 raise TypeError("Cannot update a query once a slice has been taken.")
1418 query = self.query.chain(sql.UpdateQuery)
1419 query.add_update_fields(values)
1420 # Clear any annotations so that they won't be present in subqueries.
1421 query.annotations = {}
1422 self._result_cache = None
1423 if returning_fields is None:
1424 return query.get_compiler(self.db).execute_sql(ROW_COUNT)
1425 return query.get_compiler(self.db).execute_returning_sql(returning_fields)
1426
1427 _update.alters_data = True
1428 _update.queryset_only = False

Callers 1

_do_updateMethod · 0.45

Calls 5

add_update_fieldsMethod · 0.80
get_compilerMethod · 0.80
execute_returning_sqlMethod · 0.80
chainMethod · 0.45
execute_sqlMethod · 0.45

Tested by

no test coverage detected