diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index 121797a..1f87a1b 100644
a
|
b
|
def __init__(self, verbose_name=None, name=None, primary_key=False,
|
123 | 123 | messages.update(error_messages or {}) |
124 | 124 | self.error_messages = messages |
125 | 125 | |
126 | | def __cmp__(self, other): |
| 126 | def __lt__(self, other): |
127 | 127 | # This is needed because bisect does not take a comparison function. |
128 | | return cmp(self.creation_counter, other.creation_counter) |
| 128 | if isinstance(other, Field): |
| 129 | return self.creation_counter < other.creation_counter |
| 130 | return NotImplemented |
129 | 131 | |
130 | 132 | def __deepcopy__(self, memodict): |
131 | 133 | # We don't have to deepcopy very much here, since most things are not |
diff --git a/tests/modeltests/basic/tests.py b/tests/modeltests/basic/tests.py
index f9141dc..6fa8ef7 100644
a
|
b
|
|
3 | 3 | from datetime import datetime |
4 | 4 | |
5 | 5 | from django.core.exceptions import ObjectDoesNotExist |
6 | | from django.db.models.fields import FieldDoesNotExist |
| 6 | from django.db.models.fields import Field, FieldDoesNotExist |
7 | 7 | from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature |
8 | 8 | from django.utils.translation import ugettext_lazy |
9 | 9 | |
… |
… |
def test_hash_function(self):
|
509 | 509 | |
510 | 510 | s = set([a10, a11, a12]) |
511 | 511 | self.assertTrue(Article.objects.get(headline='Article 11') in s) |
| 512 | |
| 513 | def test_field_ordering(self): |
| 514 | """ |
| 515 | Field instances have a `__lt__` comparison function to define an |
| 516 | ordering based on their creation. Prior to #17851 this ordering |
| 517 | comparison relied on the now unsupported `__cmp__` and was assuming |
| 518 | compared objects were both Field instances raising `AttributeError` |
| 519 | when it should have returned `NotImplemented`. |
| 520 | """ |
| 521 | f1 = Field() |
| 522 | f2 = Field(auto_created=True) |
| 523 | f3 = Field() |
| 524 | self.assertTrue(f2 < f1) |
| 525 | self.assertTrue(f1 < f3) |
| 526 | self.assertFalse(f1 == None) |
| 527 | self.assertFalse(f2 in (None, 1, '')) |
512 | 528 | |
513 | 529 | def test_extra_method_select_argument_with_dashes_and_values(self): |
514 | 530 | # The 'select' argument to extra() supports names with dashes in |