Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[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
@malcolmt malcolmt authored
View
3  django/db/models/fields/files.py
@@ -29,6 +29,9 @@ def __eq__(self, other):
return self.name == other.name
return self.name == other
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
# The standard File contains most of the necessary properties, but
# FieldFiles can be instantiated without a name, so that needs to
# be checked for here.
View
20 tests/regressiontests/file_storage/models.py
@@ -22,12 +22,12 @@
if Image:
class Person(models.Model):
name = models.CharField(max_length=50)
- mugshot = models.ImageField(storage=temp_storage, upload_to='tests',
- height_field='mug_height',
+ mugshot = models.ImageField(storage=temp_storage, upload_to='tests',
+ height_field='mug_height',
width_field='mug_width')
mug_height = models.PositiveSmallIntegerField()
mug_width = models.PositiveSmallIntegerField()
-
+
__test__ = {'API_TESTS': """
>>> image_data = open(os.path.join(os.path.dirname(__file__), "test.png"), 'rb').read()
@@ -42,6 +42,18 @@ class Person(models.Model):
>>> p.mug_width
16
+# Bug #9786: Ensure '==' and '!=' work correctly.
+>>> image_data = open(os.path.join(os.path.dirname(__file__), "test1.png"), 'rb').read()
+>>> p1 = Person(name="Bob")
+>>> p1.mugshot.save("mug", ContentFile(image_data))
+>>> p2 = Person.objects.get(name="Joe")
+>>> p.mugshot == p2.mugshot
+True
+>>> p.mugshot != p2.mugshot
+False
+>>> p.mugshot != p1.mugshot
+True
+
# Bug #8175: correctly delete files that have been removed off the file system.
>>> import os
>>> p2 = Person(name="Fred")
@@ -69,4 +81,4 @@ class Person(models.Model):
>>> shutil.rmtree(temp_storage_dir)
"""}
-
+
View
BIN  tests/regressiontests/file_storage/test1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Please sign in to comment.
Something went wrong with that request. Please try again.