Performs an update on the row selected by the queryset. Include values to update in the update like so: .. code-block:: python Model.objects(key=n).update(value='x') Passing in updates for columns which are not part of the model will raise a Validation
(self, **values)
| 1201 | return clone |
| 1202 | |
| 1203 | def update(self, **values): |
| 1204 | """ |
| 1205 | Performs an update on the row selected by the queryset. Include values to update in the |
| 1206 | update like so: |
| 1207 | |
| 1208 | .. code-block:: python |
| 1209 | |
| 1210 | Model.objects(key=n).update(value='x') |
| 1211 | |
| 1212 | Passing in updates for columns which are not part of the model will raise a ValidationError. |
| 1213 | |
| 1214 | Per column validation will be performed, but instance level validation will not |
| 1215 | (i.e., `Model.validate` is not called). This is sometimes referred to as a blind update. |
| 1216 | |
| 1217 | For example: |
| 1218 | |
| 1219 | .. code-block:: python |
| 1220 | |
| 1221 | class User(Model): |
| 1222 | id = Integer(primary_key=True) |
| 1223 | name = Text() |
| 1224 | |
| 1225 | setup(["localhost"], "test") |
| 1226 | sync_table(User) |
| 1227 | |
| 1228 | u = User.create(id=1, name="jon") |
| 1229 | |
| 1230 | User.objects(id=1).update(name="Steve") |
| 1231 | |
| 1232 | # sets name to null |
| 1233 | User.objects(id=1).update(name=None) |
| 1234 | |
| 1235 | |
| 1236 | Also supported is blindly adding and removing elements from container columns, |
| 1237 | without loading a model instance from Cassandra. |
| 1238 | |
| 1239 | Using the syntax `.update(column_name={x, y, z})` will overwrite the contents of the container, like updating a |
| 1240 | non container column. However, adding `__<operation>` to the end of the keyword arg, makes the update call add |
| 1241 | or remove items from the collection, without overwriting then entire column. |
| 1242 | |
| 1243 | Given the model below, here are the operations that can be performed on the different container columns: |
| 1244 | |
| 1245 | .. code-block:: python |
| 1246 | |
| 1247 | class Row(Model): |
| 1248 | row_id = columns.Integer(primary_key=True) |
| 1249 | set_column = columns.Set(Integer) |
| 1250 | list_column = columns.List(Integer) |
| 1251 | map_column = columns.Map(Integer, Integer) |
| 1252 | |
| 1253 | :class:`~cqlengine.columns.Set` |
| 1254 | |
| 1255 | - `add`: adds the elements of the given set to the column |
| 1256 | - `remove`: removes the elements of the given set to the column |
| 1257 | |
| 1258 | |
| 1259 | .. code-block:: python |
| 1260 |
nothing calls this directly
no test coverage detected