Ticket #14096: base.py.patch
File base.py.patch, 2.1 KB (added by , 14 years ago) |
---|
-
base.py
444 444 need for overrides of save() to pass around internal-only parameters 445 445 ('raw', 'cls', and 'origin'). 446 446 """ 447 newpk = False # if a new primary key is created, it is stored here for returning 447 448 using = using or router.db_for_write(self.__class__, instance=self) 448 449 connection = connections[using] 449 450 assert not (force_insert and force_update) … … 476 477 if field and getattr(self, parent._meta.pk.attname) is None and getattr(self, field.attname) is not None: 477 478 setattr(self, parent._meta.pk.attname, getattr(self, field.attname)) 478 479 479 self.save_base(cls=parent, origin=org, using=using)480 newpk = self.save_base(cls=parent, origin=org, using=using) 480 481 482 # reset primary key of the model and its parent share 483 if self.__class__._meta.pk.attname == parent._meta.pk.attname: 484 self._set_pk_val(None) 485 481 486 if field: 482 setattr(self, field.attname, self._get_pk_val(parent._meta))487 setattr(self, field.attname, newpk) 483 488 if meta.proxy: 484 489 return 485 490 … … 531 536 result = manager._insert([(meta.pk, connection.ops.pk_default_value())], return_id=update_pk, raw_values=True, using=using) 532 537 533 538 if update_pk: 534 setattr(self, meta.pk.attname, result) 539 newpk = result 540 if cls == self.__class__: 541 setattr(self, meta.pk.attname, result) 535 542 transaction.commit_unless_managed(using=using) 536 543 537 544 # Store the database on which the object was saved … … 542 549 signals.post_save.send(sender=origin, instance=self, 543 550 created=(not record_exists), raw=raw, using=using) 544 551 552 return newpk 553 545 554 save_base.alters_data = True 546 555 547 556 def _collect_sub_objects(self, seen_objs, parent=None, nullable=False):