简体   繁体   中英

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/

After Clicking on the toggle button, how to execute the query?

Line #1 means Line 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.

nsn is common on both the tables.

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. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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