MCPcopy
hub / github.com/django/django / subwidgets

Method subwidgets

django/forms/boundfield.py:31–47  ·  view source on GitHub ↗

Most widgets yield a single subwidget, but others like RadioSelect and CheckboxSelectMultiple produce one subwidget for each choice. This property is cached so that only one database query occurs when rendering ModelChoiceFields.

(self)

Source from the content-addressed store, hash-verified

29
30 @cached_property
31 def subwidgets(self):
32 """
33 Most widgets yield a single subwidget, but others like RadioSelect and
34 CheckboxSelectMultiple produce one subwidget for each choice.
35
36 This property is cached so that only one database query occurs when
37 rendering ModelChoiceFields.
38 """
39 id_ = self.field.widget.attrs.get("id") or self.auto_id
40 attrs = {"id": id_} if id_ else {}
41 attrs = self.build_widget_attrs(attrs)
42 return [
43 BoundWidget(self.field.widget, widget, self.form.renderer)
44 for widget in self.field.widget.subwidgets(
45 self.html_name, self.value(), attrs=attrs
46 )
47 ]
48
49 def __bool__(self):
50 # BoundField evaluates to True even if it doesn't have subwidgets.

Callers

nothing calls this directly

Calls 4

build_widget_attrsMethod · 0.95
valueMethod · 0.95
BoundWidgetClass · 0.85
getMethod · 0.45

Tested by

no test coverage detected