mirror of
https://github.com/django/django.git
synced 2025-07-26 22:54:17 +00:00
Fixed #13679, #13231, #7287 -- Ensured that models that have ForeignKeys/ManyToManyField can use a a callable default that returns a model instance/queryset. #13679 was a regression in behavior; the other two tickets are pleasant side effects. Thanks to 3point2 for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13577 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
d69cdc6d70
commit
b3dc3a0106
5 changed files with 122 additions and 34 deletions
|
@ -450,13 +450,14 @@ class Select(Widget):
|
|||
output.append(u'</select>')
|
||||
return mark_safe(u'\n'.join(output))
|
||||
|
||||
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>%s</option>' % (
|
||||
escape(option_value), selected_html,
|
||||
conditional_escape(force_unicode(option_label)))
|
||||
|
||||
def render_options(self, choices, selected_choices):
|
||||
def render_option(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>%s</option>' % (
|
||||
escape(option_value), selected_html,
|
||||
conditional_escape(force_unicode(option_label)))
|
||||
# Normalize to strings.
|
||||
selected_choices = set([force_unicode(v) for v in selected_choices])
|
||||
output = []
|
||||
|
@ -464,10 +465,10 @@ class Select(Widget):
|
|||
if isinstance(option_label, (list, tuple)):
|
||||
output.append(u'<optgroup label="%s">' % escape(force_unicode(option_value)))
|
||||
for option in option_label:
|
||||
output.append(render_option(*option))
|
||||
output.append(self.render_option(selected_choices, *option))
|
||||
output.append(u'</optgroup>')
|
||||
else:
|
||||
output.append(render_option(option_value, option_label))
|
||||
output.append(self.render_option(selected_choices, option_value, option_label))
|
||||
return u'\n'.join(output)
|
||||
|
||||
class NullBooleanSelect(Select):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue