diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
index 848fd6e..53f9b9f 100644
a
|
b
|
class ForeignRelatedObjectsDescriptor(object):
|
474 | 474 | def add(self, *objs): |
475 | 475 | for obj in objs: |
476 | 476 | if not isinstance(obj, self.model): |
477 | | raise TypeError("'%s' instance expected" % self.model._meta.object_name) |
| 477 | raise TypeError("'%s' instance expected, got %r" % (self.model._meta.object_name, obj)) |
478 | 478 | setattr(obj, rel_field.name, self.instance) |
479 | 479 | obj.save() |
480 | 480 | add.alters_data = True |
… |
… |
def create_many_related_manager(superclass, rel):
|
636 | 636 | (obj, self.instance._state.db, obj._state.db)) |
637 | 637 | new_ids.add(obj.pk) |
638 | 638 | elif isinstance(obj, Model): |
639 | | raise TypeError("'%s' instance expected" % self.model._meta.object_name) |
| 639 | raise TypeError("'%s' instance expected, got %r" % (self.model._meta.object_name, obj)) |
640 | 640 | else: |
641 | 641 | new_ids.add(obj) |
642 | 642 | db = router.db_for_write(self.through, instance=self.instance) |
diff --git a/tests/modeltests/many_to_many/tests.py b/tests/modeltests/many_to_many/tests.py
index b00d7da..9fa524f 100644
a
|
b
|
|
1 | | from __future__ import absolute_import |
| 1 | from __future__ import absolute_import, with_statement |
2 | 2 | |
3 | 3 | from django.test import TestCase |
4 | 4 | |
… |
… |
class ManyToManyTests(TestCase):
|
52 | 52 | ]) |
53 | 53 | |
54 | 54 | # Adding an object of the wrong type raises TypeError |
55 | | self.assertRaises(TypeError, a6.publications.add, a5) |
| 55 | with self.assertRaisesRegexp(TypeError, "'Publication' instance expected, got <Article.*"): |
| 56 | a6.publications.add(a5) |
56 | 57 | # Add a Publication directly via publications.add by using keyword arguments. |
57 | 58 | p4 = a6.publications.create(title='Highlights for Adults') |
58 | 59 | self.assertQuerysetEqual(a6.publications.all(), |
diff --git a/tests/modeltests/many_to_one/tests.py b/tests/modeltests/many_to_one/tests.py
index 922506e..bc9fe64 100644
a
|
b
|
|
1 | | from __future__ import absolute_import |
| 1 | from __future__ import absolute_import, with_statement |
2 | 2 | |
3 | 3 | from copy import deepcopy |
4 | 4 | from datetime import datetime |
… |
… |
class ManyToOneTests(TestCase):
|
68 | 68 | self.assertQuerysetEqual(self.r2.article_set.all(), ["<Article: Paul's story>"]) |
69 | 69 | |
70 | 70 | # Adding an object of the wrong type raises TypeError. |
71 | | self.assertRaises(TypeError, self.r.article_set.add, self.r2) |
| 71 | with self.assertRaisesRegexp(TypeError, "'Article' instance expected, got <Reporter.*"): |
| 72 | self.r.article_set.add(self.r2) |
72 | 73 | self.assertQuerysetEqual(self.r.article_set.all(), |
73 | 74 | [ |
74 | 75 | "<Article: John's second story>", |