diff options
| author | Eduardo Aldair Ahumada Garcia Jurado <eduardo.ahumadagj@gmail.com> | 2021-07-05 00:07:10 -0500 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-07-05 08:15:58 +0200 |
| commit | e4da3654367cd5f5c06ab109ece0042631faaa02 (patch) | |
| tree | 5fca7feaf47da8abb1790415948f7a8a0bd15c0b /django | |
| parent | fa35c8bdbc6aca65d94d6280fa463d5bc7baa5c0 (diff) | |
Refs #24121 -- Added __repr__() to AdminSite, DefaultAdminSite, and ModelAdmin.
Thanks tlebrize for the initial patch.
Diffstat (limited to 'django')
| -rw-r--r-- | django/contrib/admin/options.py | 6 | ||||
| -rw-r--r-- | django/contrib/admin/sites.py | 6 |
2 files changed, 12 insertions, 0 deletions
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index f466614061..7a5551f650 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -594,6 +594,12 @@ class ModelAdmin(BaseModelAdmin): def __str__(self): return "%s.%s" % (self.model._meta.app_label, self.__class__.__name__) + def __repr__(self): + return ( + f'<{self.__class__.__qualname__}: model={self.model.__qualname__} ' + f'site={self.admin_site!r}>' + ) + def get_inline_instances(self, request, obj=None): inline_instances = [] for inline_class in self.get_inlines(request, obj): diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py index 62c5c8a782..a87bac02bd 100644 --- a/django/contrib/admin/sites.py +++ b/django/contrib/admin/sites.py @@ -77,6 +77,9 @@ class AdminSite: self._global_actions = self._actions.copy() all_sites.add(self) + def __repr__(self): + return f'{self.__class__.__name__}(name={self.name!r})' + def check(self, app_configs): """ Run the system checks on all ModelAdmins, except if they aren't @@ -561,6 +564,9 @@ class DefaultAdminSite(LazyObject): AdminSiteClass = import_string(apps.get_app_config('admin').default_site) self._wrapped = AdminSiteClass() + def __repr__(self): + return repr(self._wrapped) + # This global object represents the default admin site, for the common case. # You can provide your own AdminSite using the (Simple)AdminConfig.default_site |
