Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.0.X] Fixed #9786 -- Fixed inequality checking for django.db.models…

….fields.file.FieldFile class.

Backport of r9647 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@9648 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0a0aba5f5eb200f8a9ccf28c62a3db852234130f 1 parent aca5a52
Malcolm Tredinnick authored December 16, 2008
3  django/db/models/fields/files.py
@@ -29,6 +29,9 @@ def __eq__(self, other):
29 29
             return self.name == other.name
30 30
         return self.name == other
31 31
 
  32
+    def __ne__(self, other):
  33
+        return not self.__eq__(other)
  34
+
32 35
     # The standard File contains most of the necessary properties, but
33 36
     # FieldFiles can be instantiated without a name, so that needs to
34 37
     # be checked for here.
20  tests/regressiontests/file_storage/models.py
@@ -22,12 +22,12 @@
22 22
 if Image:
23 23
     class Person(models.Model):
24 24
         name = models.CharField(max_length=50)
25  
-        mugshot = models.ImageField(storage=temp_storage, upload_to='tests', 
26  
-                                    height_field='mug_height', 
  25
+        mugshot = models.ImageField(storage=temp_storage, upload_to='tests',
  26
+                                    height_field='mug_height',
27 27
                                     width_field='mug_width')
28 28
         mug_height = models.PositiveSmallIntegerField()
29 29
         mug_width = models.PositiveSmallIntegerField()
30  
-        
  30
+
31 31
     __test__ = {'API_TESTS': """
32 32
 
33 33
 >>> image_data = open(os.path.join(os.path.dirname(__file__), "test.png"), 'rb').read()
@@ -42,6 +42,18 @@ class Person(models.Model):
42 42
 >>> p.mug_width
43 43
 16
44 44
 
  45
+# Bug #9786: Ensure '==' and '!=' work correctly.
  46
+>>> image_data = open(os.path.join(os.path.dirname(__file__), "test1.png"), 'rb').read()
  47
+>>> p1 = Person(name="Bob")
  48
+>>> p1.mugshot.save("mug", ContentFile(image_data))
  49
+>>> p2 = Person.objects.get(name="Joe")
  50
+>>> p.mugshot == p2.mugshot
  51
+True
  52
+>>> p.mugshot != p2.mugshot
  53
+False
  54
+>>> p.mugshot != p1.mugshot
  55
+True
  56
+
45 57
 # Bug #8175: correctly delete files that have been removed off the file system.
46 58
 >>> import os
47 59
 >>> p2 = Person(name="Fred")
@@ -69,4 +81,4 @@ class Person(models.Model):
69 81
 
70 82
 >>> shutil.rmtree(temp_storage_dir)
71 83
 """}
72  
-    
  84
+
BIN  tests/regressiontests/file_storage/test1.png

0 notes on commit 0a0aba5

Please sign in to comment.
Something went wrong with that request. Please try again.