def category_detail(request, path, page=None, **kwargs): """显示一个分类中的文章""" extra_context = kwargs.pop('extra_context', {}) category = get_category_or_404(path) if not kwargs.get('template_name'): kwargs['template_name'] = template_name_for_entry_queryset_filtered( 'category', category.slug) extra_context.update({'category': category}) kwargs['extra_context'] = extra_context matches = QuerySet ''' 这里用于获取category的下级分类的查询记录集,并进行合并,生成一个查询记录集 ''' if category.children.all(): for child in category.children.all(): try: matches = matches() | child.entries_published() except: matches = child.entries_published() matches = matches | category.entries_published() else: matches = category.entries_published() return object_list(request, queryset=matches, paginate_by=PAGINATION, page=page, **kwargs)
def category_detail(request, path, page=None, **kwargs): """显示一个分类中的文章""" extra_context = kwargs.pop('extra_context', {}) category = get_category_or_404(path) if not kwargs.get('template_name'): kwargs['template_name'] = template_name_for_entry_queryset_filtered( 'category', category.slug) extra_context.update({'category': category}) kwargs['extra_context'] = extra_context matches = QuerySet ''' 这里用于获取category的下级分类的查询记录集,并进行合并,生成一个查询记录集 ''' if category.children.all(): for child in category.children.all(): try: matches = matches() | child.entries_published() except: matches = child.entries_published() matches = matches | category.entries_published() else: matches = category.entries_published() return object_list(request, queryset=matches, paginate_by=PAGINATION, page=page, ** kwargs)
def tag_detail(request, tag, page=None, **kwargs): """Display the entries of a tag""" if not kwargs.get('template_name'): kwargs['template_name'] = template_name_for_entry_queryset_filtered( 'tag', tag) return tagged_object_list(request, tag=tag, queryset_or_model=Entry.published.all(), paginate_by=PAGINATION, page=page, **kwargs)
def author_detail(request, username, page=None, **kwargs): """Display the entries of an author""" extra_context = kwargs.pop('extra_context', {}) author = get_object_or_404(Author, username=username) if not kwargs.get('template_name'): kwargs['template_name'] = template_name_for_entry_queryset_filtered( 'author', author.username) extra_context.update({'author': author}) kwargs['extra_context'] = extra_context return object_list(request, queryset=author.entries_published(), paginate_by=PAGINATION, page=page, **kwargs)