common.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:django-driver27 作者: SRJ9 项目源码 文件源码
def render_option(self, selected_choices, option_value, option_label):
        if option_value is None:
            option_value = ''
        option_value = force_text(option_value)
        if option_value in selected_choices:
            selected_html = mark_safe(' selected="selected"')
            if not self.allow_multiple_selected:
                # Only allow for a single selection.
                selected_choices.remove(option_value)
        else:
            selected_html = ''
        data_circuit_attr = ''
        if option_value:
            from driver27.models import GrandPrix
            grand_prix = GrandPrix.objects.filter(pk=option_value)
            if grand_prix.count() and grand_prix.first().default_circuit:
                data_circuit_attr = getattr(grand_prix.first().default_circuit, 'pk', '')

        return format_html('<option value="{}"{} data-circuit="{}">{}</option>',
                           option_value, selected_html,
                           data_circuit_attr, force_text(option_label))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号