Ticket #13021: improved_update.patch
File improved_update.patch, 3.0 KB (added by , 15 years ago) |
---|
-
django/db/models/base.py
539 539 540 540 save_base.alters_data = True 541 541 542 @classmethod 543 def update(klass, queryset, updates, using=None): 544 for field in klass._meta.fields: 545 field.pre_update(queryset, updates) 546 542 547 def _collect_sub_objects(self, seen_objs, parent=None, nullable=False): 543 548 """ 544 549 Recursively populates seen_objs with all objects related to this -
django/db/models/fields/__init__.py
282 282 "Returns field's value just before saving." 283 283 return getattr(model_instance, self.attname) 284 284 285 def pre_update(self, queryset, kwargs): 286 "Do nothing by default" 287 pass 288 285 289 def get_prep_value(self, value): 286 290 "Perform preliminary non-db specific value checks and conversions." 287 291 return value … … 649 653 else: 650 654 return super(DateField, self).pre_save(model_instance, add) 651 655 656 def pre_update(self, queryset, kwargs): 657 if self.auto_now and (self.name not in kwargs): 658 kwargs[self.name] = datetime.datetime.now() 659 652 660 def contribute_to_class(self, cls, name): 653 661 super(DateField,self).contribute_to_class(cls, name) 654 662 if not self.null: -
django/db/models/signals.py
14 14 post_syncdb = Signal(providing_args=["class", "app", "created_models", "verbosity", "interactive"]) 15 15 16 16 m2m_changed = Signal(providing_args=["action", "instance", "reverse", "model", "pk_set"]) 17 18 pre_update = Signal(providing_args=["queryset", "updates"]) 19 post_update = Signal(providing_args=["queryset", "updates"]) -
django/db/models/query.py
450 450 """ 451 451 assert self.query.can_filter(), \ 452 452 "Cannot update a query once a slice has been taken." 453 signals.pre_update.send(sender=self.model, queryset=self, updates=kwargs) 453 454 self._for_write = True 454 455 query = self.query.clone(sql.UpdateQuery) 456 self.model.update(self, kwargs) 455 457 query.add_update_values(kwargs) 456 458 if not transaction.is_managed(using=self.db): 457 459 transaction.enter_transaction_management(using=self.db) … … 468 470 if forced_managed: 469 471 transaction.leave_transaction_management(using=self.db) 470 472 self._result_cache = None 473 signals.post_update.send(sender=self.model, queryset=self, updates=kwargs) 471 474 return rows 472 475 update.alters_data = True 473 476