Ticket #4102: 4102_django-1.1.patch
File 4102_django-1.1.patch, 2.0 KB (added by , 15 years ago) |
---|
-
django/db/models/base.py
240 240 class Model(object): 241 241 __metaclass__ = ModelBase 242 242 _deferred = False 243 244 def __setattr__(self, name, value): 245 if name not in self._modified_attrs: 246 if not hasattr(self, name) or value != getattr(self, name): 247 self._modified_attrs.append(name) 248 super(Model, self).__setattr__(name, value) 249 250 def _reset_modified_attrs(self): 251 self.__dict__['_modified_attrs'] = [] 243 252 244 253 def __init__(self, *args, **kwargs): 254 self._reset_modified_attrs() 245 255 signals.pre_init.send(sender=self.__class__, args=args, kwargs=kwargs) 246 256 247 257 # There is a rather weird disparity here; if kwargs, it's set, then args … … 458 468 459 469 if not meta.proxy: 460 470 non_pks = [f for f in meta.local_fields if not f.primary_key] 461 471 modified_attrs = self._modified_attrs 472 non_pks = [f for f in non_pks if (f.name in modified_attrs or f.attname in modified_attrs)] 473 self._reset_modified_attrs() 474 462 475 # First, try an UPDATE. If that doesn't update anything, do an INSERT. 463 476 pk_val = self._get_pk_val(meta) 464 477 pk_set = pk_val is not None -
django/db/models/query.py
249 249 else: 250 250 # Omit aggregates in object creation. 251 251 obj = self.model(*row[index_start:aggregate_start]) 252 # Models keep a track of modified attrs to choose which 253 # fields to save. Since we're just pulling from the 254 # database, nothing has changed yet. 255 obj._reset_modified_attrs() 252 256 253 257 for i, k in enumerate(extra_select): 254 258 setattr(obj, k, row[i])