diff --git a/django/db/models/base.py b/django/db/models/base.py
index 2e6bea8..db25494 100644
a
|
b
|
from django.utils.functional import curry
|
24 | 24 | from django.utils.encoding import smart_str, force_unicode |
25 | 25 | from django.utils.text import get_text_list, capfirst |
26 | 26 | |
| 27 | UPDATED, INSERTED = 'UPDATED', 'INSERTED' |
27 | 28 | |
28 | 29 | class ModelBase(type): |
29 | 30 | """ |
… |
… |
class Model(object):
|
473 | 474 | override this method. It's separate from save() in order to hide the |
474 | 475 | need for overrides of save() to pass around internal-only parameters |
475 | 476 | ('raw', 'cls', and 'origin'). |
| 477 | |
| 478 | Returns the action taken, which can be UPDATED or INSERTED. This is the |
| 479 | action taken for the current model. It is possible that parent model |
| 480 | was updated while current model is inserted. If the return value is |
| 481 | UPDATED, then every model in the base chain was updated. |
476 | 482 | """ |
477 | 483 | using = using or router.db_for_write(self.__class__, instance=self) |
478 | 484 | connection = connections[using] |
… |
… |
class Model(object):
|
494 | 500 | # attributes we have been given to the class we have been given. |
495 | 501 | # We also go through this process to defer the save of proxy objects |
496 | 502 | # to their actual underlying model. |
| 503 | parent_action = None |
497 | 504 | if not raw or meta.proxy: |
498 | 505 | if meta.proxy: |
499 | 506 | org = cls |
… |
… |
class Model(object):
|
506 | 513 | if field and getattr(self, parent._meta.pk.attname) is None and getattr(self, field.attname) is not None: |
507 | 514 | setattr(self, parent._meta.pk.attname, getattr(self, field.attname)) |
508 | 515 | |
509 | | self.save_base(cls=parent, origin=org, using=using) |
| 516 | parent_action = self.save_base(cls=parent, origin=org, using=using) |
510 | 517 | |
511 | 518 | if field: |
512 | 519 | setattr(self, field.attname, self._get_pk_val(parent._meta)) |
513 | 520 | if meta.proxy: |
514 | | return |
| 521 | return parent_action |
| 522 | # A small optimization: if parent was inserted, we know this model must be inserted, too. |
| 523 | if parent_action == INSERTED: |
| 524 | force_insert = True |
515 | 525 | |
516 | 526 | if not meta.proxy: |
517 | 527 | non_pks = [f for f in meta.local_fields if not f.primary_key] |
… |
… |
class Model(object):
|
546 | 556 | |
547 | 557 | elif not non_pks: |
548 | 558 | # There are no other fields than the pk in the model. In this case we do |
549 | | # not check the existense by update |
| 559 | # not check the existense by update. |
550 | 560 | if manager.using(using).filter(pk=pk_val).exists(): |
551 | 561 | record_exists = True |
552 | 562 | if not pk_set or not record_exists: |
… |
… |
class Model(object):
|
590 | 600 | signals.post_save.send(sender=origin, instance=self, |
591 | 601 | created=(not record_exists), raw=raw, using=using) |
592 | 602 | |
| 603 | if meta.proxy: |
| 604 | return parent_action |
| 605 | if record_exists: |
| 606 | return UPDATED |
| 607 | else: |
| 608 | return INSERTED |
593 | 609 | |
594 | 610 | save_base.alters_data = True |
595 | 611 | |