From 33878180d827d8d125fb48b50359384591d8d6e3 Mon Sep 17 00:00:00 2001 From: TobeTek Date: Tue, 27 Feb 2024 15:54:19 +0100 Subject: [PATCH] Fix #1688 -- Output translatable labels when displaying permissions --- django/contrib/auth/models.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py index e5ef1bb523..0eb3c5ed20 100644 --- a/django/contrib/auth/models.py +++ b/django/contrib/auth/models.py @@ -77,7 +77,18 @@ class Permission(models.Model): ordering = ["content_type__app_label", "content_type__model", "codename"] def __str__(self): - return "%s | %s" % (self.content_type, self.name) + names = {"content_type": self.content_type} + + if self.name.startswith("Can add "): + return _("%(content_type)s | Can add") % names + if self.name.startswith("Can change "): + return _("%(content_type)s | Can change") % names + if self.name.startswith("Can delete "): + return _("%(content_type)s | Can delete") % names + if self.name.startswith("Can view "): + return _("%(content_type)s | Can view") % names + + return "%s | %s" % (self.content_type, _(self.name)) def natural_key(self): return (self.codename,) + self.content_type.natural_key()