Ticket #2160: 0_pk.2.patch
File 0_pk.2.patch, 1.6 KB (added by , 18 years ago) |
---|
-
django/db/models/base.py
167 167 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 pk_set = bool(pk_val) or pk_val == 0 171 171 record_exists = True 172 172 if pk_set: 173 173 # Determine whether a record with the primary key already exists. -
docs/db-api.txt
142 142 or ``UPDATE`` SQL statements. Specifically, when you call ``save()``, Django 143 143 follows this algorithm: 144 144 145 * If the object's primary key attribute is set to a value that e valuates to146 ``True`` (i.e., a value other than ``None`` or the empty string), Django147 executes a ``SELECT`` query to determine whether a record with the given148 primary key already exists.145 * If the object's primary key attribute is set to a value that equals ``0`` 146 or evaluates to ``True`` (i.e., a value other than ``None`` or the empty 147 string), Django executes a ``SELECT`` query to determine whether a record 148 with the given primary key already exists. 149 149 * If the record with the given primary key does already exist, Django 150 150 executes an ``UPDATE`` query. 151 151 * If the object's primary key attribute is *not* set, or if it's set but a