summaryrefslogtreecommitdiff
path: root/docs/ref/class-based-views
diff options
context:
space:
mode:
authorJacek Bzdak <jbzdak@gmail.com>2015-10-21 10:28:22 +0200
committerTim Graham <timograham@gmail.com>2015-10-23 15:18:39 -0400
commit494b7986a3e5996d857b085f188a630d1504d9ca (patch)
tree12a1a314be9e6165f73c7e75afcf371ab1ef3ffd /docs/ref/class-based-views
parent484edc81c1ebd195c333f3ea8d3f9ca882a17837 (diff)
Fixed #25397 -- Documented class-based view context variable clash with context processors.
Diffstat (limited to 'docs/ref/class-based-views')
-rw-r--r--docs/ref/class-based-views/mixins-single-object.txt26
1 files changed, 20 insertions, 6 deletions
diff --git a/docs/ref/class-based-views/mixins-single-object.txt b/docs/ref/class-based-views/mixins-single-object.txt
index e7370b3ba8..02c1437526 100644
--- a/docs/ref/class-based-views/mixins-single-object.txt
+++ b/docs/ref/class-based-views/mixins-single-object.txt
@@ -102,20 +102,34 @@ SingleObjectMixin
Returns context data for displaying the list of objects.
- The base implementation of this method requires that the ``object``
+ The base implementation of this method requires that the ``self.object``
attribute be set by the view (even if ``None``). Be sure to do this if
you are using this mixin without one of the built-in views that does so.
+ It returns a dictionary with these contents:
+
+ * ``object``: The object that this view is displaying
+ (``self.object``).
+ * ``context_object_name``: ``self.object`` will also be stored under
+ the name returned by :meth:`get_context_object_name`, which defaults
+ to the lowercased version of the model name.
+
+ .. admonition:: Context variables override values from template context processors
+
+ Any variables from :meth:`get_context_data` take precedence over
+ context variables from :ref:`context processors
+ <subclassing-context-requestcontext>`. For example, if your view
+ sets the :attr:`model` attribute to
+ :class:`~django.contrib.auth.models.User`, the default context
+ object name of ``user`` would override the ``user`` variable from
+ the :func:`django.contrib.auth.context_processors.auth` context
+ processor. Use :meth:`get_context_object_name` to avoid a clash.
+
.. method:: get_slug_field()
Returns the name of a slug field to be used to look up by slug. By
default this simply returns the value of :attr:`slug_field`.
- **Context**
-
- * ``object``: The object that this view is displaying. If
- ``context_object_name`` is specified, that variable will also be
- set in the context, with the same value as ``object``.
SingleObjectTemplateResponseMixin
---------------------------------