diff --git a/django/db/models/fields/related_descriptors.py b/django/db/models/fields/related_descriptors.py
index 050866e..c732469 100644
a
|
b
|
def create_forward_many_to_many_manager(superclass, rel, reverse):
|
855 | 855 | add.alters_data = True |
856 | 856 | |
857 | 857 | def remove(self, *objs): |
858 | | if not rel.through._meta.auto_created: |
859 | | opts = self.through._meta |
860 | | raise AttributeError( |
861 | | "Cannot use remove() on a ManyToManyField which specifies " |
862 | | "an intermediary model. Use %s.%s's Manager instead." % |
863 | | (opts.app_label, opts.object_name) |
864 | | ) |
865 | 858 | self._remove_items(self.source_field_name, self.target_field_name, *objs) |
866 | 859 | remove.alters_data = True |
867 | 860 | |
diff --git a/tests/m2m_through/tests.py b/tests/m2m_through/tests.py
index 497270e..97c116e 100644
a
|
b
|
class M2mThroughTests(TestCase):
|
79 | 79 | [] |
80 | 80 | ) |
81 | 81 | |
82 | | def test_cannot_use_remove_on_m2m_with_intermediary_model(self): |
| 82 | def test_can_use_remove_on_m2m_with_intermediary_model(self): |
83 | 83 | Membership.objects.create(person=self.jim, group=self.rock) |
84 | | msg = 'Cannot use remove() on a ManyToManyField which specifies an intermediary model' |
85 | | |
86 | | with self.assertRaisesMessage(AttributeError, msg): |
87 | | self.rock.members.remove(self.jim) |
88 | | |
89 | | self.assertQuerysetEqual( |
90 | | self.rock.members.all(), |
91 | | ['Jim', ], |
92 | | attrgetter("name") |
93 | | ) |
| 84 | self.rock.members.remove(self.jim) |
| 85 | self.assertQuerysetEqual(self.rock.members.all(), []) |
94 | 86 | |
95 | 87 | def test_cannot_use_setattr_on_m2m_with_intermediary_model(self): |
96 | 88 | msg = 'Cannot set values on a ManyToManyField which specifies an intermediary model' |
… |
… |
class M2mThroughTests(TestCase):
|
148 | 140 | [] |
149 | 141 | ) |
150 | 142 | |
151 | | def test_cannot_use_remove_on_reverse_m2m_with_intermediary_model(self): |
| 143 | def test_can_use_remove_on_reverse_m2m_with_intermediary_model(self): |
152 | 144 | Membership.objects.create(person=self.bob, group=self.rock) |
153 | | msg = 'Cannot use remove() on a ManyToManyField which specifies an intermediary model' |
154 | | |
155 | | with self.assertRaisesMessage(AttributeError, msg): |
156 | | self.bob.group_set.remove(self.rock) |
157 | | |
158 | | self.assertQuerysetEqual( |
159 | | self.bob.group_set.all(), |
160 | | ['Rock', ], |
161 | | attrgetter('name') |
162 | | ) |
| 145 | self.bob.group_set.remove(self.rock) |
| 146 | self.assertQuerysetEqual(self.bob.group_set.all(), []) |
163 | 147 | |
164 | 148 | def test_cannot_use_setattr_on_reverse_m2m_with_intermediary_model(self): |
165 | 149 | msg = 'Cannot set values on a ManyToManyField which specifies an intermediary model' |