小编rab*_*ron的帖子

django ::如何在表单中设置CheckboxSelectMultiple的样式?

forms.py

class FormEntry(forms.ModelForm):
  class Meta:
    model = Entry
    fields = ['name','price','share']
    widgets = {
      'share':forms.CheckboxSelectMultiple(),
    }
Run Code Online (Sandbox Code Playgroud)

将其传递到模板后:

<ul id="id_share">
<li><label for="id_share_0"><input id="id_share_0" name="share" type="checkbox" value="2"> lily</label></li>
<li><label for="id_share_1"><input id="id_share_1" name="share" type="checkbox" value="1"> rabbit</label></li>
</ul>
Run Code Online (Sandbox Code Playgroud)

现在我想摆脱ul和li,同样,我想使用bootstrap3的按钮组来设计它,像这样的东西

<div class="btn-group" data-toggle="buttons">
  <label class="btn btn-primary">
    <input id="id_share_0" name="share" type="checkbox" value="2"> lily
  </label>
  <label class="btn btn-primary">
    <input id="id_share_1" name="share" type="checkbox" value="1"> rabbit
  </label>
</div>
Run Code Online (Sandbox Code Playgroud)

如果有人可以给我一个通用的解决方案,而不是从views.py传递特定的值,那将是理想的,我的想法是编写一个小部件,但我无法弄清楚如何.

我知道我是菜鸟,请帮忙.

css python django twitter-bootstrap-3

6
推荐指数
1
解决办法
5495
查看次数

标签 统计

css ×1

django ×1

python ×1

twitter-bootstrap-3 ×1