diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py index 9ac557ea71..43583c81e9 100644 --- a/django/contrib/admin/views/main.py +++ b/django/contrib/admin/views/main.py @@ -108,6 +108,13 @@ class ChangeList: self.title = title % self.opts.verbose_name self.pk_attname = self.lookup_opts.pk.attname + def __repr__(self): + return '<%s: model=%s model_admin=%s>' % ( + self.__class__.__qualname__, + self.model.__qualname__, + self.model_admin.__class__.__qualname__, + ) + def get_filters_params(self, params=None): """ Return all params except IGNORED_PARAMS. diff --git a/django/contrib/messages/storage/base.py b/django/contrib/messages/storage/base.py index b2eeac77f4..01422066a6 100644 --- a/django/contrib/messages/storage/base.py +++ b/django/contrib/messages/storage/base.py @@ -69,6 +69,9 @@ class BaseStorage: def __contains__(self, item): return item in self._loaded_messages or item in self._queued_messages + def __repr__(self): + return f'<{self.__class__.__qualname__}: request={self.request!r}>' + @property def _loaded_messages(self): """ diff --git a/tests/admin_changelist/tests.py b/tests/admin_changelist/tests.py index 0b8535beb7..e0486b37f8 100644 --- a/tests/admin_changelist/tests.py +++ b/tests/admin_changelist/tests.py @@ -67,6 +67,13 @@ class ChangeListTests(TestCase): request.user = user return request + def test_repr(self): + m = ChildAdmin(Child, custom_site) + request = self.factory.get('/child/') + request.user = self.superuser + cl = m.get_changelist_instance(request) + self.assertEqual(repr(cl), '') + def test_specified_ordering_by_f_expression(self): class OrderedByFBandAdmin(admin.ModelAdmin): list_display = ['name', 'genres', 'nr_of_members'] diff --git a/tests/messages_tests/base.py b/tests/messages_tests/base.py index 17fe06e2e3..9dad08e6c7 100644 --- a/tests/messages_tests/base.py +++ b/tests/messages_tests/base.py @@ -88,6 +88,14 @@ class BaseTests: storage._loaded_data = data or [] return storage + def test_repr(self): + request = self.get_request() + storage = self.storage_class(request) + self.assertEqual( + repr(storage), + f'<{self.storage_class.__qualname__}: request=>', + ) + def test_add(self): storage = self.get_storage() self.assertFalse(storage.added_new)