from django import forms
from django.utils.encoding import force_unicode
from django.utils.html import escape, conditional_escape

class SelectMultipleWithTitle(forms.SelectMultiple):
    """ multiple select optihon with title """
    def render_option(self, selected_choices, option_value, option_label):
        option_value = force_unicode(option_value)
        selected_html = (option_value in selected_choices) and u' selected="selected"' or ''
        return u'<option value="%s"%s title="%s">%s</option>' % (
            escape(option_value), selected_html,
            conditional_escape(force_unicode(option_label)),
            conditional_escape(force_unicode(option_label)))

您可能还喜欢以下文章


关于我

热爱开源、分享。目前主要从事混合云、数据库 SaaS 等运维开发及相关团队管理工作。