Vb407
Vb407

Reputation: 1607

How to create grouped dropdown list in django admin?

I want to create a grouped dropdown list in django admin.I could generate a normal drop downlist using "choices = ()".But I need something like this.

--Tools--
   Dotnet
   Vstudio
-- App --
  WMP
  Encoder
-- ABC --
   a
   b

How to achieve this?

Upvotes: 2

Views: 507

Answers (1)

ndpu
ndpu

Reputation: 22571

This format of choices tuple will do what you need:

items=(
    ("Animals", (("1","Monkey"), ("2","Turtle"))),
    ("Aliens", (("3","Zim"), ("4","Tak"))),
)

select=forms.ChoiceField(label="Selection", choices=items)

enter image description here

Upvotes: 6

Related Questions