Advertisement
ZAD-Man

Get_context_data

Sep 24th, 2014
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. def get_context_data(self, **kwargs):
  2.         """
  3.        Get the context for this view.
  4.        """
  5.         queryset = kwargs.pop('object_list', self.object_list)
  6.         page_size = self.get_paginate_by(queryset)
  7.         context_object_name = self.get_context_object_name(queryset)
  8.         if page_size:
  9.             paginator, page, queryset, is_paginated = self.paginate_queryset(queryset, page_size)
  10.             context = {
  11.                 'paginator': paginator,
  12.                 'page_obj': page,
  13.                 'is_paginated': is_paginated,
  14.                 'object_list': queryset
  15.             }
  16.         else:
  17.             context = {
  18.                 'paginator': None,
  19.                 'page_obj': None,
  20.                 'is_paginated': False,
  21.                 'object_list': queryset
  22.             }
  23.         if context_object_name is not None:
  24.             context[context_object_name] = queryset
  25.         context.update(kwargs)
  26.         return super(MultipleObjectMixin, self).get_context_data(**context)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement