Ticket #15669: ticket15669.diff

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

Updated patch with tests

  • django/contrib/admin/validation.py

    diff --git a/django/contrib/admin/validation.py b/django/contrib/admin/validation.py
    index 58a8490..9a0c948 100644
    a b def validate(cls, model):  
    104104                field = opts.get_field_by_name(field_name)[0]
    105105            except models.FieldDoesNotExist:
    106106                raise ImproperlyConfigured("'%s.list_editable[%d]' refers to a "
    107                     "field, '%s', not defined on %s."
    108                     % (cls.__name__, idx, field_name, model.__name__))
     107                    "field, '%s', not defined on %s.%s."
     108                    % (cls.__name__, idx, field_name, model._meta.app_label, model.__name__))
    109109            if field_name not in cls.list_display:
    110110                raise ImproperlyConfigured("'%s.list_editable[%d]' refers to "
    111111                    "'%s' which is not defined in 'list_display'."
    def validate_inline(cls, parent, parent_model):  
    215215        if fk and fk.name in cls.exclude:
    216216            raise ImproperlyConfigured("%s cannot exclude the field "
    217217                    "'%s' - this is the foreign key to the parent model "
    218                     "%s." % (cls.__name__, fk.name, parent_model.__name__))
     218                    "%s.%s." % (cls.__name__, fk.name, parent_model._meta.app_label, parent_model.__name__))
    219219
    220220    if hasattr(cls, "readonly_fields"):
    221221        check_readonly_fields(cls, cls.model, cls.model._meta)
    def get_field(cls, model, opts, label, field):  
    372372    try:
    373373        return opts.get_field(field)
    374374    except models.FieldDoesNotExist:
    375         raise ImproperlyConfigured("'%s.%s' refers to field '%s' that is missing from model '%s'."
    376                 % (cls.__name__, label, field, model.__name__))
     375        raise ImproperlyConfigured("'%s.%s' refers to field '%s' that is missing from model '%s.%s'."
     376                % (cls.__name__, label, field, model._meta.app_label, model.__name__))
    377377
    378378def check_formfield(cls, model, opts, label, field):
    379379    if getattr(cls.form, 'base_fields', None):
    def fetch_attr(cls, model, opts, label, field):  
    398398    try:
    399399        return getattr(model, field)
    400400    except AttributeError:
    401         raise ImproperlyConfigured("'%s.%s' refers to '%s' that is neither a field, method or property of model '%s'."
    402             % (cls.__name__, label, field, model.__name__))
     401        raise ImproperlyConfigured("'%s.%s' refers to '%s' that is neither a field, method or property of model '%s.%s'."
     402            % (cls.__name__, label, field, model._meta.app_label, model.__name__))
    403403
    404404def check_readonly_fields(cls, model, opts):
    405405    check_isseq(cls, "readonly_fields", cls.readonly_fields)
  • tests/regressiontests/admin_validation/tests.py

    diff --git a/tests/regressiontests/admin_validation/tests.py b/tests/regressiontests/admin_validation/tests.py
    index 2cf3c60..9e50a8b 100644
    a b class ValidationTestCase(TestCase):  
    9292            inlines = [SongInline]
    9393
    9494        self.assertRaisesMessage(ImproperlyConfigured,
    95             "SongInline cannot exclude the field 'album' - this is the foreign key to the parent model Album.",
     95            "SongInline cannot exclude the field 'album' - this is the foreign key to the parent model admin_validation.Album.",
    9696            validate,
    9797            AlbumAdmin, Album)
    9898
     99    def test_app_label_in_admin_validation(self):
     100        """
     101        Regression test for #15669 - Include app label in admin validation messages
     102        """
     103        class RawIdNonexistingAdmin(admin.ModelAdmin):
     104            raw_id_fields = ('nonexisting',)
     105
     106        self.assertRaisesMessage(ImproperlyConfigured,
     107            "'RawIdNonexistingAdmin.raw_id_fields' refers to field 'nonexisting' that is missing from model 'admin_validation.Album'.",
     108            validate,
     109            RawIdNonexistingAdmin, Album)
     110
    99111    def test_fk_exclusion(self):
    100112        """
    101113        Regression test for #11709 - when testing for fk excluding (when exclude is
Back to Top