Created
October 8, 2016 14:29
-
-
Save sergei-maertens/30d88e4319a8f7a62b9c50c0fa30fceb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/django/db/models/options.py b/django/db/models/options.py | |
index cd9cef7..c2e2b6b 100644 | |
--- a/django/db/models/options.py | |
+++ b/django/db/models/options.py | |
@@ -194,13 +194,12 @@ class Options(object): | |
self.index_together = normalize_together(self.index_together) | |
# Replace any %(model_name)s / %(verbose_name)s placeholders. | |
- perms = meta_attrs.pop('permissions', self.permissions) | |
+ perms = meta_attrs.pop('permissions', self.permissions) or [] | |
interpolated_perms = [] | |
- if perms: | |
- for codename, name in perms: | |
- codename %= {'class': self.model_name} | |
- name = name % {'verbose_name': self.verbose_name} | |
- interpolated_perms.append((codename, name)) | |
+ for codename, name in perms: | |
+ codename %= {'class': self.model_name} | |
+ name %= {'verbose_name': self.verbose_name} | |
+ interpolated_perms.append((codename, name)) | |
self.permissions = interpolated_perms | |
# verbose_name_plural is a special case because it uses a 's' | |
diff --git a/docs/ref/models/options.txt b/docs/ref/models/options.txt | |
index 10d34a9..2b6ea5f 100644 | |
--- a/docs/ref/models/options.txt | |
+++ b/docs/ref/models/options.txt | |
@@ -329,29 +329,29 @@ Django quotes column and table names behind the scenes. | |
This is a list or tuple of 2-tuples in the format ``(permission_code, | |
human_readable_permission_name)``. | |
- The permission code and name on an (abstract) model may contain | |
- ``%(class)s`` and ``%(verbose_name)s``. The models inheriting from the base | |
- model will then have those permissions specific to the inheriting model, | |
- e.g.:: | |
+ The permission code and name on an abstract model may contain the | |
+ ``%(class)s`` and ``%(verbose_name)s`` placeholders, respectively, which | |
+ will be filled based on the properties of the child models. For example:: | |
class Base(models.Model): | |
... | |
class Meta: | |
permissions = ( | |
- ("can_deliver_%(class)s", "Can deliver %(verbose_name)"), | |
+ ("can_deliver_%(class)s", "Can deliver %(verbose_name)s"), | |
) | |
class Pizza(Base): | |
pass | |
- The model ``Pizza`` now has the permissions ``can_deliver_pizza`` with the | |
- label "Can deliver pizza". | |
+ The ``Pizza`` model has the permission ``can_deliver_pizza`` with the label | |
+ "Can deliver pizza". | |
.. versionadded:: 1.11 | |
- The ability to use ``%(class)s`` interpolation was added. | |
+ The ability to use ``%(class)s`` and ``%(verbose_name)s`` interpolation | |
+ was added. | |
``default_permissions`` | |
------------------------------ | |
diff --git a/docs/releases/1.11.txt b/docs/releases/1.11.txt | |
index 6afed03..0df0597 100644 | |
--- a/docs/releases/1.11.txt | |
+++ b/docs/releases/1.11.txt | |
@@ -216,8 +216,9 @@ Models | |
to truncate :class:`~django.db.models.DateTimeField` to its time component | |
and exposed it through the :lookup:`time` lookup. | |
-* :attr:`~django.db.models.Options.permissions` now supports class interpolation | |
- using the ``'%(class)s'`` and ``'%(verbose_name)s'`` string. | |
+* Abstract model :attr:`Meta.permissions <django.db.models.Options.permissions>` | |
+ now support interpolation using the ``'%(class)s'`` and ``'%(verbose_name)s'`` | |
+ placeholders. | |
Requests and Responses | |
~~~~~~~~~~~~~~~~~~~~~~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment