Display a boolean model field in a django form as a radio button rather than the default Checkbox

前端 未结 4 1912
猫巷女王i
猫巷女王i 2021-02-08 06:19

This is how I went about, to display a Boolean model field in the form as Radio buttons Yes and No.

choices = ( (1,\'Yes\'),
            (0,\'No\'),
          )
         


        
4条回答
  •  走了就别回头了
    2021-02-08 06:43

    field = BooleanField(widget=RadioSelect(choices=YES_OR_NO), required=False)
    
    
    YES_OR_NO = (
        (True, 'Yes'),
        (False, 'No')
    )
    

提交回复
热议问题