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)
| 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 |
no test coverage detected