码迷,mamicode.com
首页 > 其他好文 > 详细

联表查询

时间:2017-07-23 15:31:39      阅读:245      评论:0      收藏:0      [点我收藏+]

标签:views   个人   分享   int   cond   choice   app   div   choices   

 

技术分享
<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

 

联表查询

标签:views   个人   分享   int   cond   choice   app   div   choices   

原文地址:http://www.cnblogs.com/domestique/p/7224614.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!