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

Hi guyz, 

I try to record my custom' form but i don't how to create a dictionnary ? 

Can i do sommething like that : 


@http.route('/coopaname_helpdesk/post_form_ticket/<string:model_name>',  methods=['POST'], type = 'http', auth='public',  website= True )
def website_form(self, model_name, **kwargs):

data =

 { 'my_first_input' : '%s', 'my_second_input' : '%s' }

and record with : 

return request.env.cr['my_data_table_name'].create(data) 


Thanks for yours helps my friends, 

Best regards


Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Yes but i want a dynamic value, not a static value written into the code, i want the value' input from the customer. 

So i can't define my variable before user submit the form, do you see what i mean bro ?


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

This is not a static value, you can assign the values you receiving from the form to the variables, i just have shown a sample for understanding, if you print **kwargs you will get the values from the form, from that you can get the values and assign in dictionary

Tác giả

var1 = ' '

var2 = ' '

etc etc

data = { 'my_first_input' : ' var1' , 'my_second_input' : ' var2' }

Like that ? with empty variable at the beginning ?

Tác giả

or like that :

var_x_objet_consultation = kwargs.get('x_objet_consultation')

etc etc

data = { 'x_objet_consultation' : ' var_x_objet_consultation ' }

return request.env.cr['my table database']. create(data)

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

Hi,

You can easily create a dictionary like this,

variable_1 = 'Niyas'

varibale_2 = 'Test'

data =

 { 'my_first_input' :  variable_1,

'my_second_input' : variable_2

 }


Thanks

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 8 18
4438
0
thg 7 16
3371
2
thg 9 20
11306
1
thg 11 19
8088
1
thg 11 19
4627