diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index 61fd2be..6e7abc1 100644
|
a
|
b
|
class Query(object):
|
| 1092 | 1092 | can_reuse) |
| 1093 | 1093 | return |
| 1094 | 1094 | |
| | 1095 | from django.db.models.base import Model |
| | 1096 | from django.db.models.fields.related import RelatedField |
| | 1097 | if (isinstance(field, RelatedField) and isinstance(value, Model) and |
| | 1098 | not isinstance(value, target.model)): |
| | 1099 | raise TypeError, "'%s' instance expected" % target.model._meta.object_name |
| | 1100 | |
| 1095 | 1101 | table_promote = False |
| 1096 | 1102 | join_promote = False |
| 1097 | 1103 | |
diff --git a/tests/modeltests/many_to_many/tests.py b/tests/modeltests/many_to_many/tests.py
index 39fe581..2479268 100644
|
a
|
b
|
class ManyToManyTests(TestCase):
|
| 195 | 195 | self.assertQuerysetEqual(Article.objects.exclude(publications=self.p2), |
| 196 | 196 | ['<Article: Django lets you build Web apps easily>']) |
| 197 | 197 | |
| | 198 | # Filter values on related fields are checked to ensure the correct |
| | 199 | # model class is being used. |
| | 200 | self.assertRaises(TypeError, Article.objects.filter, |
| | 201 | publications=self.a1) |
| | 202 | |
| 198 | 203 | def test_reverse_selects(self): |
| 199 | 204 | # Reverse m2m queries are supported (i.e., starting at the table that |
| 200 | 205 | # doesn't have a ManyToManyField). |
| … |
… |
class ManyToManyTests(TestCase):
|
| 245 | 250 | '<Publication: The Python Journal>', |
| 246 | 251 | ]) |
| 247 | 252 | |
| | 253 | # Filter values on related fields are checked to ensure the correct |
| | 254 | # model class is being used. |
| | 255 | self.assertRaises(TypeError, Publication.objects.filter, |
| | 256 | article=self.p1) |
| | 257 | |
| 248 | 258 | def test_delete(self): |
| 249 | 259 | # If we delete a Publication, its Articles won't be able to access it. |
| 250 | 260 | self.p1.delete() |
diff --git a/tests/modeltests/many_to_one/tests.py b/tests/modeltests/many_to_one/tests.py
index 9f60c21..053c5ee 100644
|
a
|
b
|
class ManyToOneTests(TestCase):
|
| 230 | 230 | "<Article: This is a test>", |
| 231 | 231 | ]) |
| 232 | 232 | |
| | 233 | # Filter values on related fields are checked to ensure the correct |
| | 234 | # model class is being used. |
| | 235 | self.assertRaises(TypeError, Article.objects.filter, reporter=self.a) |
| | 236 | |
| 233 | 237 | def test_reverse_selects(self): |
| 234 | 238 | a3 = Article.objects.create(id=None, headline="Third article", |
| 235 | 239 | pub_date=datetime(2005, 7, 27), reporter_id=self.r.id) |
| … |
… |
class ManyToOneTests(TestCase):
|
| 301 | 305 | list(Article.objects.filter(reporter=self.r).distinct().order_by() |
| 302 | 306 | .values('reporter__first_name', 'reporter__last_name'))) |
| 303 | 307 | |
| | 308 | # Filter values on related fields are checked to ensure the correct |
| | 309 | # model class is being used. |
| | 310 | self.assertRaises(TypeError, Reporter.objects.filter, article=self.r) |
| | 311 | |
| 304 | 312 | def test_select_related(self): |
| 305 | 313 | # Check that Article.objects.select_related().dates() works properly when |
| 306 | 314 | # there are multiple Articles with the same date but different foreign-key |
diff --git a/tests/modeltests/one_to_one/tests.py b/tests/modeltests/one_to_one/tests.py
index c3e1704..0e5724a 100644
|
a
|
b
|
class OneToOneTests(TestCase):
|
| 61 | 61 | assert_get_restaurant(place__pk=self.p1.pk) |
| 62 | 62 | assert_get_restaurant(place__name__startswith="Demon") |
| 63 | 63 | |
| | 64 | # Filter values on related fields are checked to ensure the correct |
| | 65 | # model class is being used. |
| | 66 | self.assertRaises(TypeError, Restaurant.objects.get, place=self.r) |
| | 67 | |
| 64 | 68 | def assert_get_place(**params): |
| 65 | 69 | self.assertEqual(repr(Place.objects.get(**params)), |
| 66 | 70 | '<Place: Demon Dogs the place>') |
| … |
… |
class OneToOneTests(TestCase):
|
| 75 | 79 | assert_get_place(id__exact=self.p1.pk) |
| 76 | 80 | assert_get_place(pk=self.p1.pk) |
| 77 | 81 | |
| | 82 | # Filter values on related fields are checked to ensure the correct |
| | 83 | # model class is being used. |
| | 84 | self.assertRaises(TypeError, Place.objects.get, restaurant=self.p1) |
| | 85 | |
| 78 | 86 | def test_foreign_key(self): |
| 79 | 87 | # Add a Waiter to the Restaurant. |
| 80 | 88 | w = self.r.waiter_set.create(name='Joe') |
| … |
… |
class OneToOneTests(TestCase):
|
| 89 | 97 | assert_filter_waiters(restaurant__place__exact=self.p1) |
| 90 | 98 | assert_filter_waiters(restaurant__place__pk=self.p1.pk) |
| 91 | 99 | assert_filter_waiters(restaurant__exact=self.p1.pk) |
| 92 | | assert_filter_waiters(restaurant__exact=self.p1) |
| 93 | 100 | assert_filter_waiters(restaurant__pk=self.p1.pk) |
| 94 | 101 | assert_filter_waiters(restaurant=self.p1.pk) |
| 95 | 102 | assert_filter_waiters(restaurant=self.r) |