Code

Ticket #15669: ticket15669.diff

File ticket15669.diff, 4.0 KB (added by Jure Cuhalev <gandalf@…>, 3 years ago)

Updated patch with tests

Line 
1diff --git a/django/contrib/admin/validation.py b/django/contrib/admin/validation.py
2index 58a8490..9a0c948 100644
3--- a/django/contrib/admin/validation.py
4+++ b/django/contrib/admin/validation.py
5@@ -104,8 +104,8 @@ def validate(cls, model):
6                 field = opts.get_field_by_name(field_name)[0]
7             except models.FieldDoesNotExist:
8                 raise ImproperlyConfigured("'%s.list_editable[%d]' refers to a "
9-                    "field, '%s', not defined on %s."
10-                    % (cls.__name__, idx, field_name, model.__name__))
11+                    "field, '%s', not defined on %s.%s."
12+                    % (cls.__name__, idx, field_name, model._meta.app_label, model.__name__))
13             if field_name not in cls.list_display:
14                 raise ImproperlyConfigured("'%s.list_editable[%d]' refers to "
15                     "'%s' which is not defined in 'list_display'."
16@@ -215,7 +215,7 @@ def validate_inline(cls, parent, parent_model):
17         if fk and fk.name in cls.exclude:
18             raise ImproperlyConfigured("%s cannot exclude the field "
19                     "'%s' - this is the foreign key to the parent model "
20-                    "%s." % (cls.__name__, fk.name, parent_model.__name__))
21+                    "%s.%s." % (cls.__name__, fk.name, parent_model._meta.app_label, parent_model.__name__))
22 
23     if hasattr(cls, "readonly_fields"):
24         check_readonly_fields(cls, cls.model, cls.model._meta)
25@@ -372,8 +372,8 @@ def get_field(cls, model, opts, label, field):
26     try:
27         return opts.get_field(field)
28     except models.FieldDoesNotExist:
29-        raise ImproperlyConfigured("'%s.%s' refers to field '%s' that is missing from model '%s'."
30-                % (cls.__name__, label, field, model.__name__))
31+        raise ImproperlyConfigured("'%s.%s' refers to field '%s' that is missing from model '%s.%s'."
32+                % (cls.__name__, label, field, model._meta.app_label, model.__name__))
33 
34 def check_formfield(cls, model, opts, label, field):
35     if getattr(cls.form, 'base_fields', None):
36@@ -398,8 +398,8 @@ def fetch_attr(cls, model, opts, label, field):
37     try:
38         return getattr(model, field)
39     except AttributeError:
40-        raise ImproperlyConfigured("'%s.%s' refers to '%s' that is neither a field, method or property of model '%s'."
41-            % (cls.__name__, label, field, model.__name__))
42+        raise ImproperlyConfigured("'%s.%s' refers to '%s' that is neither a field, method or property of model '%s.%s'."
43+            % (cls.__name__, label, field, model._meta.app_label, model.__name__))
44 
45 def check_readonly_fields(cls, model, opts):
46     check_isseq(cls, "readonly_fields", cls.readonly_fields)
47diff --git a/tests/regressiontests/admin_validation/tests.py b/tests/regressiontests/admin_validation/tests.py
48index 2cf3c60..9e50a8b 100644
49--- a/tests/regressiontests/admin_validation/tests.py
50+++ b/tests/regressiontests/admin_validation/tests.py
51@@ -92,10 +92,22 @@ class ValidationTestCase(TestCase):
52             inlines = [SongInline]
53 
54         self.assertRaisesMessage(ImproperlyConfigured,
55-            "SongInline cannot exclude the field 'album' - this is the foreign key to the parent model Album.",
56+            "SongInline cannot exclude the field 'album' - this is the foreign key to the parent model admin_validation.Album.",
57             validate,
58             AlbumAdmin, Album)
59 
60+    def test_app_label_in_admin_validation(self):
61+        """
62+        Regression test for #15669 - Include app label in admin validation messages
63+        """
64+        class RawIdNonexistingAdmin(admin.ModelAdmin):
65+            raw_id_fields = ('nonexisting',)
66+
67+        self.assertRaisesMessage(ImproperlyConfigured,
68+            "'RawIdNonexistingAdmin.raw_id_fields' refers to field 'nonexisting' that is missing from model 'admin_validation.Album'.",
69+            validate,
70+            RawIdNonexistingAdmin, Album)
71+
72     def test_fk_exclusion(self):
73         """
74         Regression test for #11709 - when testing for fk excluding (when exclude is