Repository: django-import-export/django-import-export

Issue:
Improve formatting of Admin UI error messages
**Describe the bug**

The Admin UI error messages are not very user friendly.  The error message below contains a lot of information which is not relevant to the user.

![Screenshot 2023-12-20 at 15 32 26](https://github.com/django-import-export/django-import-export/assets/6249838/e1dea798-4227-4834-a230-419c0b22217a)

**To Reproduce**

- Edit the file `books.csv`
- Add a column called 'author' and use a value of 99999
- Import this file and you will see the error message.


**Versions (please complete the following information):**
 - Django Import Export: 4.0.0-beta
 - Python 3.8
 - Django 5.0 
 - 
**Expected behavior**

It would be best to see a more user friendly error message.
See also #1359 





Discussion:

Resolving patch:
diff --git a/import_export/admin.py b/import_export/admin.py
--- a/import_export/admin.py
+++ b/import_export/admin.py
@@ -83,6 +83,10 @@ class ImportMixin(BaseImportMixin, ImportExportMixinBase):
     confirm_form_class = ConfirmImportForm
     #: import data encoding
     from_encoding = "utf-8-sig"
+    #: control which UI elements appear when import errors are displayed.
+    #: Available options: 'message', 'row', 'traceback'
+    import_error_display = ("message",)
+
     skip_admin_log = None
     # storage class for saving temporary files
     tmp_storage_class = None
@@ -535,6 +539,7 @@ def import_action(self, request, *args, **kwargs):
             )
             for resource in resources
         ]
+        context["import_error_display"] = self.import_error_display
 
         request.current_app = self.admin_site.name
         return TemplateResponse(request, [self.import_template_name], context)


Test patch:
diff --git a/tests/core/tests/admin_integration/test_import.py b/tests/core/tests/admin_integration/test_import.py
--- a/tests/core/tests/admin_integration/test_import.py
+++ b/tests/core/tests/admin_integration/test_import.py
@@ -1,5 +1,6 @@
 import os
 import warnings
+from io import StringIO
 from unittest import mock
 from unittest.mock import MagicMock, patch
 
@@ -9,7 +10,10 @@
 from core.tests.admin_integration.mixins import AdminTestMixin
 from core.tests.utils import ignore_widget_deprecation_warning
 from django.contrib.admin.models import DELETION, LogEntry
+from django.contrib.admin.sites import AdminSite
+from django.contrib.auth.models import User
 from django.http import HttpRequest
+from django.test import RequestFactory
 from django.test.testcases import TestCase, TransactionTestCase
 from django.test.utils import override_settings
 from django.utils.translation import gettext_lazy as _
@@ -480,6 +484,75 @@ def test_export_empty_import_formats(self):
             self.client.get(self.book_import_url)
 
 
+class TestImportErrorMessageFormat(AdminTestMixin, TestCase):
+    # issue 1724
+
+    def setUp(self):
+        super().setUp()
+        self.csvdata = "id,name,author\r\n" "1,Ulysses,666\r\n"
+        self.filedata = StringIO(self.csvdata)
+        self.data = {"format": "0", "import_file": self.filedata}
+        self.model_admin = BookAdmin(Book, AdminSite())
+
+        factory = RequestFactory()
+        self.request = factory.post(self.book_import_url, self.data, follow=True)
+        self.request.user = User.objects.create_user("admin1")
+
+    @ignore_widget_deprecation_warning
+    def test_result_error_display_default(self):
+        response = self.model_admin.import_action(self.request)
+        response.render()
+        self.assertIn("import-error-display-message", str(response.content))
+        self.assertIn(
+            "Line number: 1 - Author matching query does not exist.",
+            str(response.content),
+        )
+        self.assertNotIn("import-error-display-row", str(response.content))
+        self.assertNotIn("import-error-display-traceback", str(response.content))
+
+    @ignore_widget_deprecation_warning
+    def test_result_error_display_message_only(self):
+        self.model_admin.import_error_display = ("message",)
+
+        response = self.model_admin.import_action(self.request)
+        response.render()
+        self.assertIn(
+            "Line number: 1 - Author matching query does not exist.",
+            str(response.content),
+        )
+        self.assertIn("import-error-display-message", str(response.content))
+        self.assertNotIn("import-error-display-row", str(response.content))
+        self.assertNotIn("import-error-display-traceback", str(response.content))
+
+    @ignore_widget_deprecation_warning
+    def test_result_error_display_row_only(self):
+        self.model_admin.import_error_display = ("row",)
+
+        response = self.model_admin.import_action(self.request)
+        response.render()
+        self.assertNotIn(
+            "Line number: 1 - Author matching query does not exist.",
+            str(response.content),
+        )
+        self.assertNotIn("import-error-display-message", str(response.content))
+        self.assertIn("import-error-display-row", str(response.content))
+        self.assertNotIn("import-error-display-traceback", str(response.content))
+
+    @ignore_widget_deprecation_warning
+    def test_result_error_display_traceback_only(self):
+        self.model_admin.import_error_display = ("traceback",)
+
+        response = self.model_admin.import_action(self.request)
+        response.render()
+        self.assertNotIn(
+            "Line number: 1 - Author matching query does not exist.",
+            str(response.content),
+        )
+        self.assertNotIn("import-error-display-message", str(response.content))
+        self.assertNotIn("import-error-display-row", str(response.content))
+        self.assertIn("import-error-display-traceback", str(response.content))
+
+
 class ConfirmImportEncodingTest(AdminTestMixin, TestCase):
     """Test handling 'confirm import' step using different file encodings
     and storage types.