Ticket #25672: 25672.diff

File 25672.diff, 2.8 KB (added by Tim Graham, 9 years ago)
  • django/db/models/fields/related_descriptors.py

    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):  
    855855        add.alters_data = True
    856856
    857857        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                 )
    865858            self._remove_items(self.source_field_name, self.target_field_name, *objs)
    866859        remove.alters_data = True
    867860
  • tests/m2m_through/tests.py

    diff --git a/tests/m2m_through/tests.py b/tests/m2m_through/tests.py
    index 497270e..97c116e 100644
    a b class M2mThroughTests(TestCase):  
    7979            []
    8080        )
    8181
    82     def test_cannot_use_remove_on_m2m_with_intermediary_model(self):
     82    def test_can_use_remove_on_m2m_with_intermediary_model(self):
    8383        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(), [])
    9486
    9587    def test_cannot_use_setattr_on_m2m_with_intermediary_model(self):
    9688        msg = 'Cannot set values on a ManyToManyField which specifies an intermediary model'
    class M2mThroughTests(TestCase):  
    148140            []
    149141        )
    150142
    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):
    152144        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(), [])
    163147
    164148    def test_cannot_use_setattr_on_reverse_m2m_with_intermediary_model(self):
    165149        msg = 'Cannot set values on a ManyToManyField which specifies an intermediary model'
Back to Top