Django单选按钮自定义渲染器

时间:2011-08-15 10:16:03

标签: django radio-button custom-fields

我尝试以这种方式自定义Django中的单选按钮:

<label for="id_jobStatus_1">
    <span>
        <a rel="jobStatus" href="#"></a>
        <input type="radio" id="id_jobStatus_1" name="jobStatus" class="radio" value="1">
    </span> xxx1
</label>

<span>
      <a rel="question" href="#"></a>
      <input type="radio" checked="" value="oui" name="question" id="" >
</span>
<label class="RadioObject" style="cursor: pointer;"> xxx </label>

为了呈现第一个,我已经将自定义渲染器写为

class HorizRadioRenderer(forms.RadioSelect.renderer):
    def render(self):
        return mark_safe(u'\n'.join([u'%s\n' % w for w in self]))

但是,我无法在第二部分中实现按钮渲染。 如您所见,差异是移除label wrapper并将其放在input span wrapper之后,并将RadioObject css类添加到标签中。

实现这一目标的合适方法是什么?

0 个答案:

没有答案