Skip to content

Commit

Permalink
Add 'object' to context in SingleObjectMixin
Browse files Browse the repository at this point in the history
To match the documentation of SingleObjectMixin, if it is used separately from (Base)DetailView.
  • Loading branch information
dracos committed Apr 10, 2013
1 parent 118faa0 commit e352f70
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion django/views/generic/detail.py
Expand Up @@ -93,6 +93,8 @@ def get_context_data(self, **kwargs):
Insert the single object into the context dict.
"""
context = {}
if self.object:
context['object'] = self.object
context_object_name = self.get_context_object_name(self.object)
if context_object_name:
context[context_object_name] = self.object
Expand All @@ -106,7 +108,7 @@ class BaseDetailView(SingleObjectMixin, View):
"""
def get(self, request, *args, **kwargs):
self.object = self.get_object()
context = self.get_context_data(object=self.object)
context = self.get_context_data()
return self.render_to_response(context)


Expand Down
3 changes: 2 additions & 1 deletion tests/generic_views/base.py
Expand Up @@ -403,8 +403,9 @@ def test_get_context_data_super(self):
test_view = views.CustomContextView()
context = test_view.get_context_data(kwarg_test='kwarg_value')

# the test_name key is inserted by the test classes parent
# the test_name and object keys are inserted by the test class's parent
self.assertTrue('test_name' in context)
self.assertTrue('object' in context)
self.assertEqual(context['kwarg_test'], 'kwarg_value')
self.assertEqual(context['custom_key'], 'custom_value')

Expand Down

0 comments on commit e352f70

Please sign in to comment.