Save this instance. Records modified timestamp and user, and raises ConcurrencyError if an out-of-date version is being saved.
(self, *args, **kwargs)
| 229 | cache.delete(cache_key) |
| 230 | |
| 231 | def save(self, *args, **kwargs): |
| 232 | """ |
| 233 | Save this instance. |
| 234 | Records modified timestamp and user, and raises ConcurrencyError if an |
| 235 | out-of-date version is being saved. |
| 236 | """ |
| 237 | self.delete_modelfilter_choices_cache(self) |
| 238 | |
| 239 | if not kwargs.pop("notrack", False): |
| 240 | user = kwargs.pop("user", None) |
| 241 | now = utcnow() |
| 242 | if self.pk is None and user is not None: |
| 243 | self.creator = user |
| 244 | # .create() won't pass in user, but presets modifier |
| 245 | if not (self.pk is None and self.modifier is not None): |
| 246 | self.modifier = user |
| 247 | self.modified_time = now |
| 248 | |
| 249 | # MTModels always have an auto-PK and we don't set PKs explicitly, so |
| 250 | # we can assume that a set PK means this should be an update. |
| 251 | if kwargs.get("force_update") or self.id is not None: |
| 252 | non_pks = [f for f in self._meta.local_fields if not f.primary_key] |
| 253 | # This isn't a race condition because the save will only take |
| 254 | # effect if previous_version is actually up to date. |
| 255 | values = [(f, None, f.pre_save(self, False)) for f in non_pks] |
| 256 | rows = self.__class__.objects.filter(id=self.id)._update(values) |
| 257 | if not rows: |
| 258 | raise ConcurrencyError( |
| 259 | "No {0} row with id {1} and version {2} updated.".format( |
| 260 | self.__class__, self.id, '?') |
| 261 | ) |
| 262 | else: |
| 263 | return super(CDBaseModel, self).save(*args, **kwargs) |
| 264 | |
| 265 | def clone(self, cascade=None, overrides=None, user=None): |
| 266 | """ |
no test coverage detected