4102_Django1.3_JL20110610.patch
--- django/db/models/base.py 2011-03-14 01:45:55.000000000 -0400
+++ django/db/models/base.py 2011-06-10 07:13:11.296655297 -0400
@@ -278,6 +278,8 @@
     def __init__(self, *args, **kwargs):
         signals.pre_init.send(sender=self.__class__, args=args, kwargs=kwargs)
 
+        self._reset_modified_attrs()
+
         # Set up the storage for instance state
         self._state = ModelState()
 
@@ -368,6 +370,15 @@
         super(Model, self).__init__()
         signals.post_init.send(sender=self.__class__, instance=self)
 
+    def __setattr__(self, name, value):
+        if name not in self.__dict__.setdefault('_modified_attrs', []):
+            if not hasattr(self, name) or value != getattr(self, name):
+                self._modified_attrs.append(name)
+        super(Model, self).__setattr__(name, value)
+
+    def _reset_modified_attrs(self):
+        self.__dict__['_modified_attrs'] = []
+
     def __repr__(self):
         try:
             u = unicode(self)
@@ -465,7 +476,7 @@
     save.alters_data = True
 
     def save_base(self, raw=False, cls=None, origin=None, force_insert=False,
-            force_update=False, using=None):
+            force_update=False, using=None, modified_attrs=None):
         """
         Does the heavy-lifting involved in saving. Subclasses shouldn't need to
         override this method. It's separate from save() in order to hide the
@@ -486,6 +497,9 @@
         if origin and not meta.auto_created:
             signals.pre_save.send(sender=origin, instance=self, raw=raw, using=using)
 
+        if modified_attrs is None:
+            modified_attrs = self._modified_attrs
+
         # If we are in a raw save, save the object exactly as presented.
         # That means that we don't try to be smart about saving attributes
         # that might have come from the parent class - we just save the
@@ -504,7 +518,7 @@
                 if field and getattr(self, parent._meta.pk.attname) is None and getattr(self, field.attname) is not None:
                     setattr(self, parent._meta.pk.attname, getattr(self, field.attname))
 
-                self.save_base(cls=parent, origin=org, using=using)
+                self.save_base(cls=parent, origin=org, using=using, modified_attrs=modified_attrs)
 
                 if field:
                     setattr(self, field.attname, self._get_pk_val(parent._meta))
@@ -526,6 +540,13 @@
                     # It does already exist, so do an UPDATE.
                     if force_update or non_pks:
                         values = [(f, None, (raw and getattr(self, f.attname) or f.pre_save(self, False))) for f in non_pks]
+
+                        # Only keep modified_attrs and those whose value has changed after pre_save
+                        if self._state.db == using:
+                            values = [v for v in values
+                                      if v[0].name in modified_attrs
+                                      or v[0].attname in modified_attrs
+                                      or v[2] != getattr(self, v[0].name)]
                         rows = manager.using(using).filter(pk=pk_val)._update(values)
                         if force_update and not rows:
                             raise DatabaseError("Forced update did not affect any rows.")
@@ -562,6 +583,8 @@
                     setattr(self, meta.pk.attname, result)
             transaction.commit_unless_managed(using=using)
 
+            self._reset_modified_attrs()
+
         # Store the database on which the object was saved
         self._state.db = using
         # Once saved, this is no longer a to-be-added instance.
--- django/db/models/query.py    2011-02-12 00:23:41.000000000 -0500
+++ django/db/models/query.py    2011-06-09 10:11:30.800905942 -0400
@@ -284,6 +284,10 @@ class QuerySet(object):
                 else:
                     # Omit aggregates in object creation.
                     obj = model(*row[index_start:aggregate_start])
+                    # Models keep a track of modified attrs to choose which
+                    # fields to save. Since we're just pulling from the
+                    # database, nothing has changed yet.
+                    obj._reset_modified_attrs()
 
                 # Store the source database of the object
                 obj._state.db = db
