Changeset 4463
- Timestamp:
- 02/07/07 16:56:53 (2 years ago)
- Files:
-
- django/trunk/django/db/models/base.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/db/models/base.py
r4459 r4463 168 168 # First, try an UPDATE. If that doesn't update anything, do an INSERT. 169 169 pk_val = self._get_pk_val() 170 pk_set = bool(pk_val) 170 171 record_exists = True 171 if pk_ val is not None:172 if pk_set: 172 173 # Determine whether a record with the primary key already exists. 173 174 cursor.execute("SELECT 1 FROM %s WHERE %s=%%s LIMIT 1" % \ … … 184 185 else: 185 186 record_exists = False 186 if pk_val is Noneor not record_exists:187 if not pk_set or not record_exists: 187 188 field_names = [backend.quote_name(f.column) for f in self._meta.fields if not isinstance(f, AutoField)] 188 189 db_values = [f.get_db_prep_save(f.pre_save(self, True)) for f in self._meta.fields if not isinstance(f, AutoField)] 189 190 # If the PK has been manually set, respect that. 190 if pk_ val is not None:191 if pk_set: 191 192 field_names += [f.column for f in self._meta.fields if isinstance(f, AutoField)] 192 193 db_values += [f.get_db_prep_save(f.pre_save(self, True)) for f in self._meta.fields if isinstance(f, AutoField)] … … 208 209 backend.quote_name(self._meta.pk.column), 209 210 backend.get_pk_default_value())) 210 if self._meta.has_auto_field and pk_val is None:211 if self._meta.has_auto_field and not pk_set: 211 212 setattr(self, self._meta.pk.attname, backend.get_last_insert_id(cursor, self._meta.db_table, self._meta.pk.column)) 212 213 transaction.commit_unless_managed()
