Multi-level list (another ... I think)

37 views
Skip to first unread message

refreegrata

unread,
Sep 20, 2012, 1:53:45 PM9/20/12
to django...@googlegroups.com
Hello list
I have a question. I need to build a multi-level MultipleChoiceField. Something like this:
-------------------------------
<select>
  <optgroup label="Videogames">
    <optgroup label="PS3">
      <option value="1">Heavy Rain</option>
      <option value="2">KOF XIII</option>
    </optgroup>
    <optgroup label="XBox">
      <option value="3">Halo 3</option>
    </optgroup>
  </optgroup>
  <optgroup label="Comics">
    <optgroup label="DC">
      <option value="4">Watchmen</option>
      <option value="5">Swamp thing</option>
    </optgroup>
    <optgroup label="Marvel">
      <option value="6">Spiderman</option>
    </optgroup>
  </optgroup>
</select>
-------------------------------
With just one level (1 optgroup) is easy, but optgroups inside other optgroups ... I don't know how.

I'm trying this: 

------------------
    myChoices= (
                ('Videogames', (
                                ('PS3', (
                                         ('1', 'Heavy Rain'),
                                         ('2', 'KOF XIII')
                                )),
                                ('XBox', (
                                          ('3', 'Halo 3')
                                ))
                               ),
                ),
                ('Comics', (
                            ('DC', (
                                    ('4', 'Watchmen'),
                                    ('5', 'Swamp thing')
                            )),
                            ('Marvel', (
                                        ('6', 'Spiderman')
                            ))
                           )
                )
               )

......
self.fields['myList'].choices= self.myChoices
------------------------------

But don't works

Somebody have an idea?

That's all. Bye
Reply all
Reply to author
Forward
0 new messages