Ticket #4102: 4102-dirty.2.patch
File 4102-dirty.2.patch, 1.7 KB (added by , 17 years ago) |
---|
-
django/db/models/base.py
94 94 def __ne__(self, other): 95 95 return not self.__eq__(other) 96 96 97 _dirty = {} 98 99 def __setattr__(self, name, value): 100 if name != '_dirty' and value != getattr(self, name): 101 self._dirty[name] = True 102 super(Model, self).__setattr__(name, value) 103 104 def _wash(self): 105 self._dirty = {} 106 97 107 def __init__(self, *args, **kwargs): 98 108 dispatcher.send(signal=signals.pre_init, sender=self.__class__, args=args, kwargs=kwargs) 99 109 100 110 # There is a rather weird disparity here; if kwargs, it's set, then args 101 111 # overrides it. It should be one or the other; don't duplicate the work 102 112 # The reason for the kwargs check is that standard iterator passes in by … … 164 174 pass 165 175 if kwargs: 166 176 raise TypeError, "'%s' is an invalid keyword argument for this function" % kwargs.keys()[0] 177 178 self._wash() 167 179 dispatcher.send(signal=signals.post_init, sender=self.__class__, instance=self) 168 180 169 181 def add_to_class(cls, name, value): … … 201 213 def save(self): 202 214 dispatcher.send(signal=signals.pre_save, sender=self.__class__, instance=self) 203 215 204 non_pks = [f for f in self._meta.fields if not f.primary_key] 216 non_pks = [f for f in self._meta.fields if not f.primary_key and (self._dirty.get(f.name, False) or self._dirty.get(f.attname, False))] 217 self._wash() 205 218 cursor = connection.cursor() 206 219 207 220 # First, try an UPDATE. If that doesn't update anything, do an INSERT.