Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


how to write multiple value in dictionary ???

mihir shah
on 5/8/14, 12:46 PM 1,007 views

hi there

metal_vals = {'die_variant_id': []}

      for revision in die.die_line_id:
      for metal in revision.metal_lines:
          metal_vals['die_variant_id'] += [[0,0, {'revision_id': revision.id}]]
              metal_vals['die_variant_id'] += [[0,0, {'metal_id': metal.metal_id.id}]]

      self.write(cr, uid, [die.id], metal_vals, context=context)

i want to write both revision_id and metal_id in in same variable i.e metal_vals

What would be the proper syntax for the same

Could you be more specific? What kind of data structure do you have? What's up with the list of list with two zeros and a dict?

Miku Laitinen
on 5/8/14, 1:32 PM
shashank verma
On 5/8/14, 1:40 PM


metal_vals has following O/P->

{'die_variant_id': [[0, 0, {'revision_id': 1}], [0, 0, {'metal_id': 2}]]}

So what exactly you wan to write ? you already have 2ids in your dictionary

On 5/8/14, 1:58 PM

you can create a list variable and add different elements to it inside the for loop like so

complete_list = []
for metal in revision.metal_lines:
    revision_list = [0,0, {'revision_id': revision.id}]
    metal_list = [0,0, {'metal_id': metal.metal_id.id}]
    group_list = [revision_list, metal_list]
    complete_list.append( group_list )

Then you can add the complete list to your dictionary variable like this:

metal_vals = { 'die_variant_id': complete_list }

Is this what you are looking for? Hope it helps

But group_list will print same thing i guess:

>> [[0, 0, {'revision_id': 1}], [0, 0, {'metal_id': 2}]]}

so again metal_vals={'die_variant_id': [[0, 0, {'revision_id': 1}], [0, 0, {'metal_id': 2}]]}

;-) ;-)

shashank verma
on 5/8/14, 2:08 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)


Asked: 5/8/14, 12:46 PM
Seen: 1007 times
Last updated: 3/16/15, 8:10 AM