Added a test for QuerySet.update() with a ManyToManyField.

This commit is contained in:
Tim Graham 2017-07-07 13:01:38 -04:00
parent 23c529a774
commit a8c70abfdf
2 changed files with 10 additions and 0 deletions

View File

@ -46,3 +46,4 @@ class Foo(models.Model):
class Bar(models.Model):
foo = models.ForeignKey(Foo, models.CASCADE, to_field='target')
m2m_foo = models.ManyToManyField(Foo, related_name='m2m_foo')

View File

@ -139,6 +139,15 @@ class AdvancedTests(TestCase):
bar_qs.update(foo=b_foo)
self.assertEqual(bar_qs[0].foo_id, b_foo.target)
def test_update_m2m_field(self):
msg = (
'Cannot update model field '
'<django.db.models.fields.related.ManyToManyField: m2m_foo> '
'(only non-relations and foreign keys permitted).'
)
with self.assertRaisesMessage(FieldError, msg):
Bar.objects.update(m2m_foo='whatever')
def test_update_annotated_queryset(self):
"""
Update of a queryset that's been annotated.