Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
4156 Tampilan

Hello ;


Dumb question maybe but...


I'm looking for the way to "send"/"put in place" default values inside each fields of my form (in the website part).

I have tried this way ( and it's ok ✔), if i prepare each default value in specifics variables and then place each field name with the good variable : 


  return request.render("module_name.id_of_the_form", 

       {            

         'first_name': user_connected_name,

         'email': mail_user_connected

       })


With this way, each field in my form have the good default value needed ( one variable by field).


⚠ But I wish to know why this one bellow doesn't works, when i use a variable as a dictionary  :


 default_values = {}        

default_values['first_name'] = request.env.user.partner_id.name        

default_values['email'] = request.env.user.partner_id.email        

 
        return request.render( "module_name.id_of_the_form ",  {default_values : 'default_values'])



The default_values dictionary contain all the informations needed to be put in place in the form, but the form didn't take thoses informations.


Thanks for your help :)

Avatar
Buang
Jawaban Terbai

You can do it using dictionary as below:

default_values = {}
default_values['first_name'] = request.env.user.partner_id.name
default_values['email'] = request.env.user.partner_id.email
return request.render( "module_name.id_of_the_form ",default_values)

or 

default_values = {'first_name':request.env.user.partner_id.name,
'email': request.env.user.partner_id.email }
return request.render( "module_name.id_of_the_form ",default_values)


Avatar
Buang
Penulis Jawaban Terbai

Hello Waleed ; 

Thanks  a lot for your response.

✔ The second one is the good for me :-)


Create the dictionnary with the rights values inside at once.

default_values = {'first_name':request.env.user.partner_id.name,
'email': request.env.user.partner_id.email }
return request.render( "module_name.id_of_the_form ",default_values)


Thanks :-)


Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
1
Nov 20
6491
0
Feb 21
3569
2
Mei 25
9697
3
Mar 24
5317
1
Jan 21
3375