繁体   English   中英

单击切换按钮后如何执行 django 或 SQL 查询?

[英]How to execute a django or SQL query after clicking the toggle button?

我有两张桌子:

class DibbsSpiderDibbsMatchedProductFieldsDuplicate(models.Model):
    nsn = models.TextField()
    nsn2 = models.TextField()
    cage = models.TextField()
    part_number = models.TextField()
    company_name = models.TextField(blank=True, null=True)
    supplier = models.TextField(db_column='Supplier', blank=True, null=True)  # Field name made lowercase.
    cost = models.CharField(db_column='Cost', max_length=15, blank=True, null=True)  # Field name made lowercase.
    list_price = models.CharField(db_column='List_Price', max_length=15, blank=True, null=True)  # Field name made lowercase.
    gsa_price = models.CharField(db_column='GSA_Price', max_length=15, blank=True, null=True)  # Field name made lowercase.
    hash = models.TextField()
    nomenclature = models.TextField()
    technical_documents = models.TextField()
    solicitation = models.CharField(max_length=32)
    status = models.CharField(max_length=16)
    purchase_request = models.TextField()
    issued = models.DateField()
    return_by = models.DateField()
    file = models.TextField()
    vendor_part_number = models.TextField()
    manufacturer_name = models.TextField(blank=True, null=True)
    product_name = models.TextField(blank=True, null=True)
    unit = models.CharField(max_length=15, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'dibbs_spider_dibbs_matched_product_fields_duplicate'


class DibbsSpiderSolicitation(models.Model):
    line_items = models.IntegerField()
    nsn = models.TextField()
    nomenclature = models.TextField()
    technical_documents = models.TextField()
    purchase_request = models.TextField()

    class Meta:
        managed = False
        db_table = 'dibbs_spider_solicitation'

我想以以下格式显示这些:

在此处输入图像描述

原文链接在: http://develop-330.gsa-cs.com/test/

单击切换按钮后,如何执行查询?

第 1 行表示行 line_items

第一行是第一个表。

单击切换按钮后,我想执行一个 django 查询或一个 sql 查询,因为它们有共同的 nsn。

nsn在两个表中都很常见。

如果有更多行项目,则应重复连接查询。

按钮代码:

<td onclick="showHideRow('switch_1');">
                        <button type="button" class="btn btn-default" data-toggle="collapse"></button>
                     </td>

您无法在 html 文件中执行 sql 查询。 如果你想这样做,你可以在urls.py中添加一个新的 url 并在views.py中添加一个 function 来发送连接表查询,然后返回结果。

You can do this by ajax GET request (in the ajax success function you can add or replace the data received from view.py with the current data in html) In jQuery you can wait for the toggle event, after clicking the toggle button you can向 url 发送 ajax 请求。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM