[英]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.