mirror of https://github.com/django/django.git
Refs #18823 -- Corrected field name in an m2m manager error message.
This commit is contained in:
parent
39a8843802
commit
b8741c0058
|
@ -814,15 +814,17 @@ def create_forward_many_to_many_manager(superclass, rel, reverse):
|
|||
self.target_field = self.through._meta.get_field(self.target_field_name)
|
||||
|
||||
self.core_filters = {}
|
||||
self.pk_field_names = {}
|
||||
for lh_field, rh_field in self.source_field.related_fields:
|
||||
core_filter_key = '%s__%s' % (self.query_field_name, rh_field.name)
|
||||
self.core_filters[core_filter_key] = getattr(instance, rh_field.attname)
|
||||
self.pk_field_names[lh_field.name] = rh_field.name
|
||||
|
||||
self.related_val = self.source_field.get_foreign_related_value(instance)
|
||||
if None in self.related_val:
|
||||
raise ValueError('"%r" needs to have a value for field "%s" before '
|
||||
'this many-to-many relationship can be used.' %
|
||||
(instance, self.source_field_name))
|
||||
(instance, self.pk_field_names[self.source_field_name]))
|
||||
# Even if this relation is not to pk, we require still pk value.
|
||||
# The wish is that the instance has been already saved to DB,
|
||||
# although having a pk value isn't a guarantee of that.
|
||||
|
|
|
@ -216,7 +216,7 @@ class ToFieldThroughTests(TestCase):
|
|||
def test_m2m_relations_unsable_on_null_to_field(self):
|
||||
nullcar = Car(make=None)
|
||||
msg = (
|
||||
'"<Car: None>" needs to have a value for field "car" before this '
|
||||
'"<Car: None>" needs to have a value for field "make" before this '
|
||||
'many-to-many relationship can be used.'
|
||||
)
|
||||
with self.assertRaisesMessage(ValueError, msg):
|
||||
|
@ -258,7 +258,7 @@ class ToFieldThroughTests(TestCase):
|
|||
def test_add_null_reverse_related(self):
|
||||
nulldriver = Driver.objects.create(name=None)
|
||||
msg = (
|
||||
'"<Driver: None>" needs to have a value for field "driver" before '
|
||||
'"<Driver: None>" needs to have a value for field "name" before '
|
||||
'this many-to-many relationship can be used.'
|
||||
)
|
||||
with self.assertRaisesMessage(ValueError, msg):
|
||||
|
|
Loading…
Reference in New Issue