简体   繁体   English

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

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

I have two tables:我有两张桌子:

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'

I want to display these in the format:我想以以下格式显示这些:

在此处输入图像描述

The original link is on: http://develop-330.gsa-cs.com/test/原文链接在: http://develop-330.gsa-cs.com/test/

After Clicking on the toggle button, how to execute the query?单击切换按钮后,如何执行查询?

Line #1 means Line line_items第 1 行表示行 line_items

First row is of first table.第一行是第一个表。

After clicking on the toggle, I want to execute a django query or a sql query which joins two tables since they have common nsn.单击切换按钮后,我想执行一个 django 查询或一个 sql 查询,因为它们有共同的 nsn。

nsn is common on both the tables. nsn在两个表中都很常见。

If there are more line items, the joined query should repeat.如果有更多行项目,则应重复连接查询。

code of button:按钮代码:

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

You can't execute sql query in the html file.您无法在 html 文件中执行 sql 查询。 if you want to do this, you can add a new url in urls.py and a function in views.py to send the join table query and then return the result.如果你想这样做,你可以在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 send a ajax request to the url. 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.

相关问题 单击 HTML (Django) 中的按钮后,如何执行 python 脚本? - How to execute a python script after clicking a button in HTML (Django)? Django:点击按钮后调用方法 - Django: call method after clicking button 如何在html页面上单击按钮执行python代码,并在Django的同一页面上显示结果? - How to execute a python code on clicking a button on html page and show the results on the same page in Django? 如何在单击后禁用按钮并在登录过程完成后通过在django中检查服务器响应来启用按钮 - How to disable a button after clicking it and enable it after the login process is completed by checking the server response in django Plotly:如何使用类似于在图例中单击它们的按钮来切换轨迹? - Plotly: How to toggle traces with a button similar to clicking them in legend? 如何在 Django 中执行 PostgreSQL 查询 - How to execute PostgreSQL query in Django 单击Django中的单选按钮后如何在同一页面上显示数据 - How Can I Display Data on same page after clicking radio button in Django 如何通过单击链接而不是按钮向电报机器人发送查询? - How to send query to telegrambot by clicking a link, not a button? Django Stripe 支付在点击提交支付按钮后没有响应 - Django Stripe payment does not respond after clicking the Submit Payment button 单击提交按钮 django 后无法重定向到另一个页面 - Not able to redirect to another page after clicking on submit button django
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM