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)
| 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. |
nothing calls this directly
no test coverage detected