簡體   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