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))
评论列表
文章目录