Align radio buttons horizontally in django forms

前端 未结 7 1772
借酒劲吻你
借酒劲吻你 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 = '<li ' + css_style + '>{choice_value}{sub_widgets}</li>'
    

    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.

    0 讨论(0)
提交回复
热议问题