Select ALL products

已查看 58 次
跳至第一个未读帖子

Ayron Rangel

未读,
2018年6月4日 15:11:052018/6/4
收件人 web2py-users
Guys, me again o.O


How can I select all products according to the same model? I'm using modal to show the products (When I click on Magnifying Glass)


Follow my code:

Controller:
def table_stock():
    somar = db.products.unit_price.sum()
    count = db.products.id.count()
    query = (db.stock.id == db.products.stock)
    results = db(query).select(db.products.ALL, db.stock.ALL,count,somar, groupby=db.products.model)

    view = db(db.stock.id == db.products.stock).select(db.products.ALL)
    return locals()

View:

<table id="data-table-simple" class="responsive-table display" cellspacing="2">
                <thead>
                    <tr>
                        <th data-field="id">Product Code</th>
                        <th data-field="name_model">Product Model</th>
                        <th data-field="name_manufacturer">Product Manufacturer</th>
                        <th data-field="minimum_qtd">Minimum Qtd</th>
                        <th data-field="current_qtd">Current Qtd</th>
                        <th data-field="max_qtd">Max Qtd</th>
                        <th data-field="somar">Total Price</th>
                        <th style="background-image: none;"></th>
                    </tr>
                </thead>

                <tfoot>
                    <tr>
                        <th data-field="id">Product Code</th>
                        <th data-field="name_model">Product Model</th>
                        <th data-field="name_manufacturer">Product Manufacturer</th>
                        <th data-field="minimum_qtd">Minimum Qtd</th>
                        <th data-field="current_qtd">Current Qtd</th>
                        <th data-field="max_qtd">Max Qtd</th>
                        <th data-field="somar">Total Price</th>
                        <th style="background-image: none;"></th>
                    </tr>
                </tfoot>
                <tbody>
                    {{for row in results:}}
                    <tr>
                        <td>{{=row.products.id}}</td>
                        <td>{{=row.products.model.name_model}}</td>
                        <td>{{=row.products.manufacturer.name_manufacturer}}</td>
                        <td>{{=row.stock.minimum_qtd}}</td>
                        <td>{{=row[count]}}</td>
                        <td>{{=row.stock.max_qtd}}</td>
                        <td>$ {{=row[somar]}}</td>
                        <td style="width: 10%;">
                            <a id="products" class="modal-trigger" href="#view_products" title="products" style="    position: absolute; margin: -19px 37px;font-size: 26px;"><i class="mdi-action-find-in-page" style="color: #000;"></i></a>
                        </td>
                    </tr>
                    {{pass}}
                </tbody>
            </table>



Massimo Di Pierro

未读,
2018年6月14日 21:52:122018/6/14
收件人 web2py-users
t is not clear what you want to do. Can you explain without code the relation between your tables and the behavior you want to see?

Ayron Rangel

未读,
2018年6月18日 09:44:132018/6/18
收件人 web2py-users
Massime, 

I would like it to show on the "modal" the list of all models products equal to the table row. Ex.:
I have in my first row of the table all products with the model A (in query i'm using group by = 'db(query).select(db.products.ALL, db.stock.ALL,count,somar, groupby=db.products.model')). So appears just the product model name.

In the same row, when i click in the icon, i want to list all products with the same "group by model". 

Did u get it?

Val K

未读,
2018年6月18日 15:31:152018/6/18
收件人 web2py-users
You should perform an ajax request to pass model  (id or name) to the controller that would perform corresponding query  like  db((db.stock.id == db.products.stock) & (db.products.model==request.args(0)) ).select(db.products.ALL) and return it back
You can use the same controller to do it with this simple logic:
if not request.args(0):  # url is .../table_stock
   
<return group-by-list>
else: # url is .../table_stock/some_model
   
<return product-list-by-some_model>

and, of course, you have to write some js-code
回复全部
回复作者
转发
0 个新帖子