mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Made model fields comparable to other objects
Fixed #17851 -- Added __lt__ and @total_ordering to models.Field, made sure these work correctly on other objects than Field, too.
This commit is contained in:
committed by
Anssi Kääriäinen
parent
1aae1cba99
commit
5cbfb48b92
@@ -3,7 +3,7 @@ from __future__ import absolute_import
|
||||
from datetime import datetime
|
||||
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.db.models.fields import FieldDoesNotExist
|
||||
from django.db.models.fields import Field, FieldDoesNotExist
|
||||
from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
|
||||
from django.utils.translation import ugettext_lazy
|
||||
|
||||
@@ -520,6 +520,22 @@ class ModelTest(TestCase):
|
||||
s = set([a10, a11, a12])
|
||||
self.assertTrue(Article.objects.get(headline='Article 11') in s)
|
||||
|
||||
def test_field_ordering(self):
|
||||
"""
|
||||
Field instances have a `__lt__` comparison function to define an
|
||||
ordering based on their creation. Prior to #17851 this ordering
|
||||
comparison relied on the now unsupported `__cmp__` and was assuming
|
||||
compared objects were both Field instances raising `AttributeError`
|
||||
when it should have returned `NotImplemented`.
|
||||
"""
|
||||
f1 = Field()
|
||||
f2 = Field(auto_created=True)
|
||||
f3 = Field()
|
||||
self.assertTrue(f2 < f1)
|
||||
self.assertTrue(f3 > f1)
|
||||
self.assertFalse(f1 == None)
|
||||
self.assertFalse(f2 in (None, 1, ''))
|
||||
|
||||
def test_extra_method_select_argument_with_dashes_and_values(self):
|
||||
# The 'select' argument to extra() supports names with dashes in
|
||||
# them, as long as you use values().
|
||||
|
||||
Reference in New Issue
Block a user