Align radio buttons horizontally in django forms

前端 未结 7 1785
借酒劲吻你
借酒劲吻你 2021-02-08 01:50

HI

I want to align the radio buttons horizontally. By default django forms displays in vertical format.

feature_type  = forms.TypedChoiceField(choices =         


        
7条回答
  •  难免孤独
    2021-02-08 02:56

    Modified forms.RadioSelect:

    class HorizontalRadioSelect(forms.RadioSelect):
    
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
    
            css_style = 'style="display: inline-block; margin-right: 10px;"'
    
            self.renderer.inner_html = '
  • {choice_value}{sub_widgets}
  • '

    Working with on the Python 3.4 with the standart admin of the Django 1.10

    and the Django-Suit(http://djangosuit.com/) (it use Bootstrap`s 2 styles)

    Not tested for the Django-grappelli, yet.

提交回复
热议问题