Index: django/db/models/fields/files.py
===================================================================
--- django/db/models/fields/files.py	(revision 9834)
+++ django/db/models/fields/files.py	(working copy)
@@ -132,7 +132,7 @@
             # have the FieldFile interface added to them
             file_copy = copy.copy(file)
             file_copy.__class__ = type(file.__class__.__name__, 
-                                       (file.__class__, FieldFile), {})
+                                       (file.__class__, self.field.attr_class), {})
             file_copy.instance = instance
             file_copy.field = self.field
             file_copy.storage = self.field.storage
Index: tests/modeltests/model_forms/test2.png
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: tests/modeltests/model_forms/test2.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Index: tests/modeltests/model_forms/models.py
===================================================================
--- tests/modeltests/model_forms/models.py	(revision 9834)
+++ tests/modeltests/model_forms/models.py	(working copy)
@@ -110,14 +110,41 @@
         # for PyPy, you need to check for the underlying modules
         # If PIL is not available, this test is equivalent to TextFile above.
         from PIL import Image, _imaging
-        image = models.ImageField(storage=temp_storage, upload_to=custom_upload_path)
+        image = models.ImageField(storage=temp_storage, upload_to=custom_upload_path,
+                                  width_field='width', height_field='height')
+        width = models.IntegerField(editable=False)
+        height = models.IntegerField(editable=False)
     except ImportError:
         image = models.FileField(storage=temp_storage, upload_to=custom_upload_path)
     path = models.CharField(max_length=16, blank=True, default='')
 
     def __unicode__(self):
         return self.description
+    
+class OptionalImageFile(models.Model):
+    def custom_upload_path(self, filename):
+        path = self.path or 'tests'
+        return '%s/%s' % (path, filename)
+    
+    description = models.CharField(max_length=20)
+    try:
+        # If PIL is available, try testing PIL.
+        # Checking for the existence of Image is enough for CPython, but
+        # for PyPy, you need to check for the underlying modules
+        # If PIL is not available, this test is equivalent to TextFile above.
+        from PIL import Image, _imaging
+        image = models.ImageField(storage=temp_storage, upload_to=custom_upload_path,
+                                  width_field='width', height_field='height', 
+                                  blank=True, null=True)
+        width = models.IntegerField(editable=False, null=True)
+        height = models.IntegerField(editable=False, null=True)
+    except ImportError:
+        image = models.FileField(storage=temp_storage, upload_to=custom_upload_path)
+    path = models.CharField(max_length=16, blank=True, default='')
 
+    def __unicode__(self):
+        return self.description
+
 class CommaSeparatedInteger(models.Model):
     field = models.CommaSeparatedIntegerField(max_length=20)
 
@@ -1056,6 +1083,7 @@
 ...         model = ImageFile
 
 >>> image_data = open(os.path.join(os.path.dirname(__file__), "test.png"), 'rb').read()
+>>> image_data2 = open(os.path.join(os.path.dirname(__file__), "test2.png"), 'rb').read()
 
 >>> f = ImageFileForm(data={'description': u'An image'}, files={'image': SimpleUploadedFile('test.png', image_data)})
 >>> f.is_valid()
@@ -1065,6 +1093,10 @@
 >>> instance = f.save()
 >>> instance.image
 <...FieldFile: tests/test.png>
+>>> instance.width
+16
+>>> instance.height
+16
 
 # Delete the current file since this is not done by Django.
 >>> instance.image.delete()
@@ -1077,6 +1109,10 @@
 >>> instance = f.save()
 >>> instance.image
 <...FieldFile: tests/test.png>
+>>> instance.width
+16
+>>> instance.height
+16
 
 # Edit an instance that already has the image defined in the model. This will not
 # save the image again, but leave it exactly as it is.
@@ -1089,6 +1125,10 @@
 >>> instance = f.save()
 >>> instance.image
 <...FieldFile: tests/test.png>
+>>> instance.height
+16
+>>> instance.width
+16
 
 # Delete the current image since this is not done by Django.
 
@@ -1102,17 +1142,25 @@
 >>> instance = f.save()
 >>> instance.image
 <...FieldFile: tests/test2.png>
+>>> instance.height
+16
+>>> instance.width
+16
 
 # Delete the current file since this is not done by Django.
 >>> instance.image.delete()
 >>> instance.delete()
 
->>> f = ImageFileForm(data={'description': u'Changed it'}, files={'image': SimpleUploadedFile('test2.png', image_data)})
+>>> f = ImageFileForm(data={'description': u'Changed it'}, files={'image': SimpleUploadedFile('test2.png', image_data2)})
 >>> f.is_valid()
 True
 >>> instance = f.save()
 >>> instance.image
 <...FieldFile: tests/test2.png>
+>>> instance.height
+32
+>>> instance.width
+48
 
 # Delete the current file since this is not done by Django.
 >>> instance.image.delete()
@@ -1120,31 +1168,44 @@
 
 # Test the non-required ImageField
 
->>> f = ImageFileForm(data={'description': u'Test'})
->>> f.fields['image'].required = False
+>>> class OptionalImageFileForm(ModelForm):
+...     class Meta:
+...         model = OptionalImageFile
+
+>>> f = OptionalImageFileForm(data={'description': u'Test'})
 >>> f.is_valid()
 True
 >>> instance = f.save()
 >>> instance.image
 <...FieldFile: None>
+>>> instance.width
+>>> instance.height
 
->>> f = ImageFileForm(data={'description': u'And a final one'}, files={'image': SimpleUploadedFile('test3.png', image_data)}, instance=instance)
+>>> f = OptionalImageFileForm(data={'description': u'And a final one'}, files={'image': SimpleUploadedFile('test3.png', image_data)}, instance=instance)
 >>> f.is_valid()
 True
 >>> instance = f.save()
 >>> instance.image
 <...FieldFile: tests/test3.png>
+>>> instance.width
+16
+>>> instance.height
+16
 
 # Delete the current file since this is not done by Django.
 >>> instance.image.delete()
 >>> instance.delete()
 
->>> f = ImageFileForm(data={'description': u'And a final one'}, files={'image': SimpleUploadedFile('test3.png', image_data)})
+>>> f = OptionalImageFileForm(data={'description': u'And a final one'}, files={'image': SimpleUploadedFile('test4.png', image_data2)})
 >>> f.is_valid()
 True
 >>> instance = f.save()
 >>> instance.image
-<...FieldFile: tests/test3.png>
+<...FieldFile: tests/test4.png>
+>>> instance.width
+48
+>>> instance.height
+32
 >>> instance.delete()
 
 # Test callable upload_to behavior that's dependent on the value of another field in the model
