Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django - ChoiceField - Option Buttons instead of Select box

Is it possible to display the option buttons instead of select box (in the admin interface) for ChoiceField? Any suggestions?

like image 751
Sivasubramaniam Arunachalam Avatar asked Feb 26 '23 19:02

Sivasubramaniam Arunachalam


2 Answers

The following ModelAdmin subclass (in your admin.py) does what you're after:

class PersonAdmin(admin.ModelAdmin):
    radio_fields = {"group": admin.VERTICAL}

HORIZONTAL is also possible.

From the Django docs.

like image 126
jbaums Avatar answered Apr 27 '23 13:04

jbaums


There's a snippet on djangosnippets that seems to do something like this for forms given a list of choices, but it doesn't seem to specifically do it for the admin app. You might be able to either leverage this or the ideas within it to get you the rest of the way though.

like image 29
Daniel DiPaolo Avatar answered Apr 27 '23 11:04

Daniel DiPaolo