我尝试以这种方式自定义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类添加到标签中。
实现这一目标的合适方法是什么?