523 | | if pk_set: |
524 | | # Determine whether a record with the primary key already exists. |
525 | | if (force_update or (not force_insert and |
526 | | manager.using(using).filter(pk=pk_val).exists())): |
527 | | # It does already exist, so do an UPDATE. |
528 | | if force_update or non_pks: |
529 | | values = [(f, None, (raw and getattr(self, f.attname) or f.pre_save(self, False))) for f in non_pks] |
530 | | rows = manager.using(using).filter(pk=pk_val)._update(values) |
531 | | if force_update and not rows: |
532 | | raise DatabaseError("Forced update did not affect any rows.") |
533 | | else: |
534 | | record_exists = False |
| 522 | if pk_set and not force_insert: |
| 523 | # Try to update the object. If something is updated, we know the record |
| 524 | # existed. If not, we know it did not exists. |
| 525 | if force_update or non_pks: |
| 526 | values = [(f, None, (raw and getattr(self, f.attname) or f.pre_save(self, False))) for f in non_pks] |
| 527 | rows = manager.using(using).filter(pk=pk_val)._update(values) |
| 528 | if rows: |
| 529 | record_exists = True |
| 530 | if not rows and force_update: |
| 531 | raise DatabaseError("Forced update did not affect any rows.") |
| 532 | |
| 533 | elif not non_pks: |
| 534 | # There are no other fields than the pk in the model. In this case we do |
| 535 | # not check the existense by update |
| 536 | if manager.using(using).filter(pk=pk_val).exists(): |
| 537 | record_exists = True |