• 组合筛选


    <div>
            <div><span class="glyphicon glyphicon-search" aria-hidden="true"></span> 搜索条件</div>
            <div class="condition">
                大分类:
                {% if kwargs.article_type_id == 0 %}
                    <a class="active"
                       href="/backstage/{{ site }}-0-{{ kwargs.category_id }}-{{ kwargs.article2tag__tag_id }}.html">全部</a>
                {% else %}
                    <a href="/backstage/{{ site }}-0-{{ kwargs.category_id }}-{{ kwargs.article2tag__tag_id }}.html">全部</a>
                {% endif %}
                {% for row in type_list %}
                    {% if row.0 == kwargs.article_type_id %}
                        <a class="active"
                           href="/backstage/{{ site }}-{{ row.0 }}-{{ kwargs.category_id }}-{{ kwargs.article2tag__tag_id }}.html">{{ row.1 }}</a>
                    {% else %}
                        <a href="/backstage/{{ site }}-{{ row.0 }}-{{ kwargs.category_id }}-{{ kwargs.article2tag__tag_id }}.html">{{ row.1 }}</a>
                    {% endif %}
                {% endfor %}
            </div>
            <div class="condition">
                个人分类:
                {% if kwargs.category_id == 0 %}
                    <a class="active"
                       href="/backstage/{{ site }}-{{ kwargs.article_type_id }}-0-{{ kwargs.article2tag__tag_id }}.html">全部</a>
                {% else %}
                    <a href="/backstage/{{ site }}-{{ kwargs.article_type_id }}-0-{{ kwargs.article2tag__tag_id }}.html">全部</a>
                {% endif %}
                {% for row in category_list %}
                    {% if row.nid == kwargs.category_id %}
                        <a class="active"
                           href="/backstage/{{ site }}-{{ kwargs.article_type_id }}-{{ row.nid }}-{{ kwargs.article2tag__tag_id }}.html">{{ row.title }}</a>
                    {% else %}
                        <a href="/backstage/{{ site }}-{{ kwargs.article_type_id }}-{{ row.nid }}-{{ kwargs.article2tag__tag_id }}.html">{{ row.title }}</a>
                    {% endif %}
                {% endfor %}
            </div>
            <div class="condition">
                个人标签:
                {% if kwargs.article2tag__tag_id == 0 %}
                    <a class="active"
                       href="/backstage/{{ site }}-{{ kwargs.article_type_id }}-{{ kwargs.category_id }}-0.html">全部</a>
                {% else %}
                    <a href="/backstage/{{ site }}-{{ kwargs.article_type_id }}-{{ kwargs.category_id }}-0.html">全部</a>
                {% endif %}
                {% for row in tag_list %}
                    {% if row.nid == kwargs.article2tag__tag_id %}
                        <a class="active"
                           href="/backstage/{{ site }}-{{ kwargs.article_type_id }}-{{ kwargs.category_id }}-{{ row.nid }}.html">{{ row.title }}</a>
                    {% else %}
                        <a href="/backstage/{{ site }}-{{ kwargs.article_type_id }}-{{ kwargs.category_id }}-{{ row.nid }}.html">{{ row.title }}</a>
                    {% endif %}
                {% endfor %}
            </div>
    
            <div class="add_article"><a class="right" href="/add_article-{{ user_info.nid }}-{{ blog_info.nid }}.html"><span class="glyphicon glyphicon-plus"
                                                                    aria-hidden="true"></span>创建新文章</a></div>
            <div class="article_list">
                <table class="table table-hover">
                    <tr>
                        <th>文章标题</th>
                        <th colspan="2">操作</th>
                    </tr>
                    {% for article in article_list %}
                        <tr>
                            <td><a href="/perblog/{{ blog_info.site }}/article/{{ article.nid }}.html">{{ article.title }}</a></td>
                            <td><a href="/edi_article-{{ user_info.nid }}-{{ blog_info.nid }}-{{ article.nid }}.html">编辑</a></td>
                            <td><a href="/del_article-{{ user_info.nid }}-{{ blog_info.nid }}-{{ article.nid }}.html">删除</a></td>
                        </tr>
                    {% endfor %}
                </table>
            </div>
        </
    HTML
    from django.shortcuts import render, HttpResponse,redirect
    from app01 import models
    
    def backstage(request,**kwargs):
        """
        组合删选
        :param request:
        :param kwargs: 前端传过来的定位数字是字符串,要转换成整型
        :return:
        """
        condition = {}
        for k,v in kwargs.items():
            if k != "site":
                kwargs[k] = int(v)
                if v != "0":
                    condition[k] = int(v)
        username = request.session.get("username")
        user_info = models.UserInfo.objects.filter(username=username).first()
        site = kwargs.get("site")
        blog_info = models.Blog.objects.filter(site=site).first()
        # 大分类
        type_list = models.Article.type_choices
        # 个人分类
        category_list = models.Category.objects.filter(blog__site=site)
        # 个人标签
        tag_list= models.Tag.objects.filter(blog__site=site)
        condition["blog_id"] = blog_info.nid
        article_list = models.Article.objects.filter(**condition)
    
        return render(request, 'back_article.html', {"user_info": user_info,
                                                      "condition": condition,
                                                     'blog_info':blog_info,
                                                      "site": site,
                                                      'type_list': type_list,
                                                      'category_list': category_list,
                                                      'tag_list': tag_list,
                                                      'article_list': article_list,
                                                      'kwargs': kwargs
    
                                                    })
    Views
  • 相关阅读:
    Review Python装饰器
    Python自动化开发三元运算 列表解析 生成器表达式
    Python自动化开发函数02
    Python自动化开发函数03
    Python自动化开发文件
    ELK02ELK收集Linux系统平台应用系统日志
    ELK01Elasticsearch
    html5调用摄像头并拍照
    Docker 安装 PostgreSQL
    《TensorFlow+Keras自然语言处理实战》图书介绍
  • 原文地址:https://www.cnblogs.com/domestique/p/7224614.html
Copyright © 2020-2023  润新知