Index: django/db/models/base.py
===================================================================
--- django/db/models/base.py	(revision 6251)
+++ django/db/models/base.py	(working copy)
@@ -380,10 +380,23 @@
             pass
         filename = field.get_filename(filename)
 
-        # If the filename already exists, keep adding an underscore to the name of
-        # the file until the filename doesn't exist.
-        while os.path.exists(os.path.join(settings.MEDIA_ROOT, filename)):
+        # Generate a unique filename
+        while True:
+            full_filename = os.path.join(settings.MEDIA_ROOT, filename)
             try:
+                # Try and open our filename, but only if it doesn't exist 
+                # and we can open it exclusively. This won't necessarily work on
+                # NFS and some other networked filesystems, but will be ok in normal
+                # cases.
+                fd = os.open(full_filename, os.O_RDWR | os.O_CREAT | os.O_EXCL)
+                break;
+            except OSError, e:
+                # Someone else grabbed this name already
+                pass
+
+            # If the filename already exists, keep adding an underscore to the name of
+            # the file until the filename doesn't exist.
+            try:
                 dot_index = filename.rindex('.')
             except ValueError: # filename has no dot
                 filename += '_'
@@ -393,8 +406,7 @@
         # Write the file to disk.
         setattr(self, field.attname, filename)
 
-        full_filename = self._get_FIELD_filename(field)
-        fp = open(full_filename, 'wb')
+        fp = os.fdopen(fd, 'w+b')
         fp.write(raw_contents)
         fp.close()
 
