Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
7597 Lượt xem

hi,

i have one model called "product" 

product

fields : title,description,timestamp

now i want to pass timestamp as a kw in route  and access  them in controller and pass in query of product and get product objects and pass them in template in odoo 10

url:  /product/101233.00/

so it search product record for timestamp of 101233.00  in odoo and return product object 

Ảnh đại diện
Huỷ bỏ

plz clarify your question that what you want to do?

Câu trả lời hay nhất

Please find here an example that should help you...


@http.route('/product/<field>/<value>', type='http', auth="public", website=True) 
def get_product_by_name(self, field, value, **kw):
        assert field in ('name', 'description_sale', 'create_date')
        prod = request.env['product.product'].search([(field, 'ilike', value)])
        if prod:
            return json.dumps(prod.read(['name', 'create_date', 'description_sale']))
        else:
            return "Product not found"


    # http://127.0.0.3:8069/product/create_date/2017-02-16 16:48

        => will return products create at "2017-02-16 16:48"

    # http://127.0.0.3:8069/product/name/ipod

        => will return products with "ipod" in name

    # http://127.0.0.3:8069/product/description_sale/wifi

        => will return products with "wifi" in the description

Ảnh đại diện
Huỷ bỏ
Tác giả

thanks a lot its work

Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 7 19
15297
0
thg 11 23
1953
2
thg 9 20
11917
1
thg 11 19
8621
0
thg 5 19
5092