mirror of
https://github.com/django/django.git
synced 2024-11-28 21:43:13 +01:00
Fixed #35569 -- Improved wording of invalid ForeignKey error message.
This commit is contained in:
parent
704192e478
commit
31837dbcb3
@ -929,7 +929,9 @@ class ForeignKey(ForeignObject):
|
|||||||
|
|
||||||
empty_strings_allowed = False
|
empty_strings_allowed = False
|
||||||
default_error_messages = {
|
default_error_messages = {
|
||||||
"invalid": _("%(model)s instance with %(field)s %(value)r does not exist.")
|
"invalid": _(
|
||||||
|
"%(model)s instance with %(field)s %(value)r is not a valid choice."
|
||||||
|
)
|
||||||
}
|
}
|
||||||
description = _("Foreign Key (type determined by related field)")
|
description = _("Foreign Key (type determined by related field)")
|
||||||
|
|
||||||
|
@ -523,7 +523,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase):
|
|||||||
self.assertEqual(u.group, group)
|
self.assertEqual(u.group, group)
|
||||||
|
|
||||||
non_existent_email = "mymail2@gmail.com"
|
non_existent_email = "mymail2@gmail.com"
|
||||||
msg = "email instance with email %r does not exist." % non_existent_email
|
msg = "email instance with email %r is not a valid choice." % non_existent_email
|
||||||
with self.assertRaisesMessage(CommandError, msg):
|
with self.assertRaisesMessage(CommandError, msg):
|
||||||
call_command(
|
call_command(
|
||||||
"createsuperuser",
|
"createsuperuser",
|
||||||
@ -594,7 +594,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase):
|
|||||||
email = Email.objects.create(email="mymail@gmail.com")
|
email = Email.objects.create(email="mymail@gmail.com")
|
||||||
Group.objects.all().delete()
|
Group.objects.all().delete()
|
||||||
nonexistent_group_id = 1
|
nonexistent_group_id = 1
|
||||||
msg = f"group instance with id {nonexistent_group_id} does not exist."
|
msg = f"group instance with id {nonexistent_group_id} is not a valid choice."
|
||||||
|
|
||||||
with self.assertRaisesMessage(CommandError, msg):
|
with self.assertRaisesMessage(CommandError, msg):
|
||||||
call_command(
|
call_command(
|
||||||
@ -611,7 +611,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase):
|
|||||||
email = Email.objects.create(email="mymail@gmail.com")
|
email = Email.objects.create(email="mymail@gmail.com")
|
||||||
Group.objects.all().delete()
|
Group.objects.all().delete()
|
||||||
nonexistent_group_id = 1
|
nonexistent_group_id = 1
|
||||||
msg = f"group instance with id {nonexistent_group_id} does not exist."
|
msg = f"group instance with id {nonexistent_group_id} is not a valid choice."
|
||||||
|
|
||||||
with mock.patch.dict(
|
with mock.patch.dict(
|
||||||
os.environ,
|
os.environ,
|
||||||
@ -631,7 +631,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase):
|
|||||||
email = Email.objects.create(email="mymail@gmail.com")
|
email = Email.objects.create(email="mymail@gmail.com")
|
||||||
Group.objects.all().delete()
|
Group.objects.all().delete()
|
||||||
nonexistent_group_id = 1
|
nonexistent_group_id = 1
|
||||||
msg = f"group instance with id {nonexistent_group_id} does not exist."
|
msg = f"group instance with id {nonexistent_group_id} is not a valid choice."
|
||||||
|
|
||||||
@mock_inputs(
|
@mock_inputs(
|
||||||
{
|
{
|
||||||
|
@ -31,15 +31,18 @@ class BaseModelValidationTests(ValidationAssertions, TestCase):
|
|||||||
self.assertFieldFailsValidationWithMessage(
|
self.assertFieldFailsValidationWithMessage(
|
||||||
mtv.full_clean,
|
mtv.full_clean,
|
||||||
"parent",
|
"parent",
|
||||||
["model to validate instance with id %r does not exist." % mtv.parent_id],
|
[
|
||||||
|
"model to validate instance with id %r is not a valid choice."
|
||||||
|
% mtv.parent_id
|
||||||
|
],
|
||||||
)
|
)
|
||||||
mtv = ModelToValidate(number=10, name="Some Name", ufm_id="Some Name")
|
mtv = ModelToValidate(number=10, name="Some Name", ufm_id="Some Name")
|
||||||
self.assertFieldFailsValidationWithMessage(
|
self.assertFieldFailsValidationWithMessage(
|
||||||
mtv.full_clean,
|
mtv.full_clean,
|
||||||
"ufm",
|
"ufm",
|
||||||
[
|
[
|
||||||
"unique fields model instance with unique_charfield %r does not exist."
|
"unique fields model instance with unique_charfield %r is not "
|
||||||
% mtv.name
|
"a valid choice." % mtv.name
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user